dioc 0.1.0 copy "dioc: ^0.1.0" to clipboard
dioc: ^0.1.0 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 AppBootsrapper extends Bootsrapper {
  @Provide(Service, MockService)
  Container development();

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

/// Could be generated by <dioc_generator>

class _AppBootsrapper implements AppBootsrapper {
  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 AppBootsrapperBuilder  {
  static final AppBootsrapper instance = build();
  static AppBootsrapper build() => _AppBootsrapper();
}

// Main

main() {

}
3
likes
0
pub points
10%
popularity

Publisher

unverified uploader

Inversion of control based on dependency injection through containers.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

More

Packages that depend on dioc