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

DInjection is a lightweight DI library inspired by .NET Service Collection

DInjection 🗄️ #

GitHub Workflow Status (with event)

DInjection is a lightweight DI library inspired by .NET Service Collection and Service Provider.

Features #

  • ✅ Global services scope
  • ✅ Singleton & Transient lifetimes
  • ✅ Register base types
  • ✅ Get all types of base
  • ✅ High Performance

Examples #

Basic usage:

//
final services = ServicesCollection() //
    .add((_) => ServiceA())
    .build();

//
final service = services.getOf<ServiceA>();

//
service.foo();

Global services:

//
final services = ServicesCollection() //
    .add((_) => ServiceA())
    .build()
    .setGlobal();

//
functionWithNoParameters();

//
void functionWithNoParameters() {
  final service = gServices.getOf<ServiceA>();
  service.foo();
}

Base type :

//
final services = ServicesCollection() //
    .base<BaseServiceA>((base) => base.add((services) => ServiceA()))
    .build();

//
final service = services.getOf<BaseServiceA>();

//
service.foo();

Get all types of base :

//
final services = ServicesCollection() //
      .base<BaseServiceA>((base) => base //
          .add((services) => ServiceA())
          .add((services) => ServiceB()))
      .build();

//
final base = services.getManyOf<BaseServiceA>();

//
for (var b in base) {
  b.foo();
}

Perfomance #

Here is a perfomance chart of other libraries performing get for transient and singelton.

Alt text

1
likes
130
points
26
downloads

Publisher

unverified uploader

Weekly Downloads

DInjection is a lightweight DI library inspired by .NET Service Collection

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

More

Packages that depend on dinjection