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

outdatedDart 1 only

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 = new Container();
    container.register(OtherService, (c) => new OtherService(c.singleton(Service)));
    return container;
  }

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

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

class AppBootsrapperBuilder  {
  static final AppBootsrapper instance = build();
  static AppBootsrapper build() => new _AppBootsrapper();
}

// Main

main() {

}
3
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Inversion of control based on dependency injection through containers.

Homepage

License

unknown (LICENSE)

More

Packages that depend on dioc