velix_di 1.1.0 copy "velix_di: ^1.1.0" to clipboard
velix_di: ^1.1.0 copied to clipboard

a flutter dependency injection framework that implements containers that assemble and control object lifecycle as in spring.

example/main.dart

import 'package:velix_di/velix_di.dart';

import 'main.types.g.dart';

@Module(includeSubdirectories: false)
class TestModule {
  @Create()
  ConfigurationManager createConfigurationManager() {
    return ConfigurationManager();
  }

  @Create()
  ConfigurationValues createConfigurationValues() {
    return ConfigurationValues({
      "foo": {
        "bar": "4711"
      }
    });
  }
}

@Injectable(scope: "singleton", eager: true)
class Bar {
  const Bar();
}

@Injectable(factory: false)
class Baz {
  const Baz();
}

@Injectable(scope: "environment")
class Foo {
  // instance data

  final Bar bar;

  const Foo({required this.bar});
}

@Injectable(scope: "singleton", eager: true)
class Factory {
  const Factory();

  @OnInit()
  void onInit(Environment environment) {
    print("onInit $environment");
  }

  @OnDestroy()
  void onDestroy() {
    print("onDestroy");
  }

  @Inject()
  void setFoo(Foo foo, @Value("foo.bar", defaultValue: 1) int value) {
    print(foo);
  }

  @Create()
  Baz createBaz(Bar bar) {
    return Baz();
  }

}

void main() {
  // bootstrap velix

  Velix.bootstrap;

  // register types

  registerAllDescriptors();

  var environment = Environment(forModule: TestModule);

  var bar = environment.get<Foo>();
  print(bar);
}
0
likes
140
points
456
downloads

Publisher

unverified uploader

Weekly Downloads

a flutter dependency injection framework that implements containers that assemble and control object lifecycle as in spring.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, build, flutter, glob, intl, path, source_gen, stack_trace, velix

More

Packages that depend on velix_di