miodi 0.3.1 copy "miodi: ^0.3.1" to clipboard
miodi: ^0.3.1 copied to clipboard

discontinued
outdated

Dependency Injection tools for Dart.

miodi #

Dependency Injection tools for Dart.

This library aims to easily manage dependencies in your business logic components.

The project is in beta testing, please write about all the errors found.

https://pub.dartlang.org/packages/miodi

Docs #

Documentation coming soon, please wait.

Example #

Added example project. Pls check for future updates for more information. https://github.com/Miolin/miodi/tree/master/example

Create component:


class AppComponent extends MiodiComponent {
  final String param;

  AppComponent(this.param);

  @override
  List<MiodiModule> get modules => [
        module([
          singleton(Database, () => DatabaseImpl()),
          factory(User, () => User())
        ]),
        module([
          singleton(Logger, () => FileLogger(param)),
          factory(LogSender, () => LogSender(get())),
        ])
      ];
}

abstract class Database {}

class DatabaseImpl implements Database {}

class User {}

abstract class Logger {}

class FileLogger implements Logger {
  final String tag;
  FileLogger(this.tag);
}

class LogSender {
  final Logger logger;
  LogSender(this.logger);
}

In the body of the component, use the get() method to get dependencies (from the current or other modules). You can use several components. You can also use the component's constructor to represent dependencies in modules.

Usage example:

final appComponent = AppComponent('TAG');

void main() async {
  Miodi.init([appComponent]);

  Database database = Miodi.inject();
  User user = Miodi.inject();
  
  
  ScopeObject scopeObject = Miodi.inject();
  
  //and use 'injectAsync' if object creation takes time or requires delays
  Logger fileLogger = await Miodi.injectAsync();

  LogSender sender = Miodi.inject();
  sender.sendLog();
}

1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Dependency Injection tools for Dart.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta

More

Packages that depend on miodi