dioc 0.1.4 copy "dioc: ^0.1.4" to clipboard
dioc: ^0.1.4 copied to clipboard

outdated

Inversion of control based on dependency injection through containers.

example/dioc_example.dart

import 'dart:async';
import 'package:dioc/dioc.dart';

abstract class Service {
  Future<String> getContent(String id);
}

class MockService implements Service {
  @override
  Future<String> getContent(String id) async => "TEST";
}


class OtherService {

  final Service dependency;

  OtherService(this.dependency);
}


class WebService implements Service {
  @override
  Future<String> getContent(String id) async => "TEST";
}


@Provide.implemented(OtherService)
abstract class AppBootstrapper extends Bootstrapper {
  @Provide(Service, MockService)
  Container development();

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

/// Could be generated by <dioc_generator>

class _AppBootstrapper implements AppBootstrapper {
  Container base() {
    final container = Container();
    container.register<OtherService>((c) => OtherService(c.singleton<Service>()));
    return container;
  }

  Container development() {
    final container = base();
    container.register<Service>((c) => MockService());
    return container;
  }

  Container production() {
    final container = base();
    container.register<Service>((c) => WebService());
    return container;
  }
}

class AppBootstrapperBuilder  {
  static final AppBootstrapper instance = build();
  static AppBootstrapper build() => _AppBootstrapper();
}

// Main

main() {

}
3
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Inversion of control based on dependency injection through containers.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

More

Packages that depend on dioc