miodi 0.2.5

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new60

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 {
  static String testScope = 'test';
  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())),
          scope(testScope, ScopeObject, () => ScopeObject())
        ])
      ];
}

class ScopeObject {}

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 = inject();
  //if you have a lot of big components override method 'String get componentNamespace' in your components
  //this will speed up the search for dependencies
  User user = inject('customComponentNamespace');
  
  
  ScopeObject scopeObject = scopeInject(AppComponent.testScope);
  
  //For cleaning of scopes it is NECESSARY!! use cleaning methods.
  //otherwise they will work as singleton
  clearScope(AppComponent.testScope);
  
  //and use 'injectAsync' if object creation takes time or requires delays
  Logger fileLogger = await injectAsync();

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

Please be careful when using scopeInject. Scopes in status progress.

If you have ideas on how to implement self-cleaning scopes , please contact me for prompt implementation.

[0.2.5] - 05.11.2018

  • Added more information in readme

[0.2.4] - 05.11.2018

  • Added example project

[0.2.3] - 05.11.2018

  • Hotfix get dependency in component

[0.2.2] - 03.11.2018

  • Hotfix remove default scope, add optional delay before clear scope obj (delay in progress)

[0.2.1] - 03.11.2018

  • Add default scope, add optional delay before clear scope obj

[0.2.0] - 03.11.2018

  • Add custom scopes

[0.1.2] - 01.11.2018

  • Fix lib/miodi.dart

[0.1.1] - 01.11.2018

  • Miodi beta-version added correct errors

[0.0.1] - 01.11.2018

  • Miodi beta-version

example/README.md

A sample command-line application.

Created from templates made available by Stagehand under a BSD-style license.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  miodi: ^0.2.5

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:miodi/miodi.dart';
  
Version Uploaded Documentation Archive
0.2.5 Nov 5, 2018 Go to the documentation of miodi 0.2.5 Download miodi 0.2.5 archive
0.2.4 Nov 5, 2018 Go to the documentation of miodi 0.2.4 Download miodi 0.2.4 archive
0.2.2 Nov 3, 2018 Go to the documentation of miodi 0.2.2 Download miodi 0.2.2 archive
0.2.1 Nov 3, 2018 Go to the documentation of miodi 0.2.1 Download miodi 0.2.1 archive
0.2.0 Nov 3, 2018 Go to the documentation of miodi 0.2.0 Download miodi 0.2.0 archive
0.1.2 Nov 1, 2018 Go to the documentation of miodi 0.1.2 Download miodi 0.1.2 archive
0.1.1 Nov 1, 2018 Go to the documentation of miodi 0.1.1 Download miodi 0.1.1 archive
0.0.1 Nov 1, 2018 Go to the documentation of miodi 0.0.1 Download miodi 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
60
Learn more about scoring.

We analyzed this package on Nov 14, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.6

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:miodi/miodi.dart.

Health suggestions

Format lib/core/component.dart.

Run dartfmt to format lib/core/component.dart.

Format lib/core/configuration.dart.

Run dartfmt to format lib/core/configuration.dart.

Format lib/core/consts.dart.

Run dartfmt to format lib/core/consts.dart.

Fix additional 4 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/core/module.dart (Run dartfmt to format lib/core/module.dart.)
  • lib/core/providers.dart (Run dartfmt to format lib/core/providers.dart.)
  • lib/error/errors.dart (Run dartfmt to format lib/error/errors.dart.)
  • lib/miodi.dart (Run dartfmt to format lib/miodi.dart.)

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
Dev dependencies
test ^1.5.0