dioc_generator 0.1.2 copy "dioc_generator: ^0.1.2" to clipboard
dioc_generator: ^0.1.2 copied to clipboard

outdated

A generator of code for dioc containers.

dioc_generator #

A generator of code for dioc containers.

Usage #

All registrations are made by annotating a partial bootstrapper class.

Various environments could be declared as methods that return a Container. You have to decorate these methods with Provide annotations to register dependencies.

library example;

import 'package:dioc/src/container.dart';
import 'package:dioc/src/built_container.dart';

part "example.g.dart";

@bootstrapper
@Provide.implemented(OtherService) // Default registration for all environments
abstract class AppBootstrapper extends Bootstrapper {

  @Provide(Service, MockService)
  Container development();

  @Provide(Service, WebService)
  Container production();
}

To indicate how to inject dependencies, you have two options : specifying a default mode, or declaring specific injections.

For a default inject mode, add it to the Provide constructor.

@bootstrapper
@Provide.implemented(OtherService)
abstract class AppBootstrapper extends Bootstrapper {
  @Provide(Service, MockService, defaultMode: InjectMode.singleton)
  Container development();
}

Getting an instances and default injections will then use the default mode :

final service = container<Service>(); // singleton

Decorate your class fields with Inject annotations (and @inject, @singleton shortcuts) to declare specific injections.

class OtherService {
  @inject
  final Service dependency;

  @singleton
  final Service dependency2;

  OtherService(this.dependency,{this.dependency2});
}

To trigger code generation, run the command :

pub run build_runner build

Then simply use the provided builder to create your Container.

final container = AppBootstrapperBuilder.instance.development();

A complete example is also available.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A generator of code for dioc containers.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, build, build_runner, build_test, code_builder, dart_style, dioc, source_gen

More

Packages that depend on dioc_generator