dioc 0.1.6

Dart native js
Flutter Android iOS web

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() {

}
1
likes
100
pub points
81%
popularity

Inversion of control based on dependency injection through containers.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

alois.deniel@gmail.com

License

MIT (LICENSE)

More

Packages that depend on dioc