async_injector 0.1.2+2
async_injector: ^0.1.2+2

discontinued

dependency injector with async initialization support. See README for more information.

Dependency injector with async initialization support

A simple usage example

import 'package:async_injector/async_injector.dart';

class DI {
  static Provider instance;

  static initProvider() async {
    var builder = ProviderBuilder();
    //preference
    builder
      ..moduleImpl((_) => SharedPreferences.getInstance())
      ..moduleImpl((provider) => PreferenceImpl(provider.get()));
    //api
    builder
      ..moduleImpl((provider) => AuthInterceptor(provider.get()))
      ..module(DioModule());

    instance = await builder.build();
  }

  static T get<T>() => instance.get<T>();

}

After build use get method by request type

SharedPreferences preference = DI.get()

You can return Future to the module and the result from it is added to the area

 ..moduleImpl((provider) => SharedPreferences.getInstance())
 

If need to provide super class from value, set this class in type

  ..moduleImpl<ApiGateway>((provider) => ApiGatewayImpl(provider.get()))
0
likes
0
pub points
0%
popularity

dependency injector with async initialization support. See README for more information.

Repository (GitLab)
View/report issues

Documentation

API reference

Uploader

princesakenny98@gmail.com

Dependencies

flutter

More

Packages that depend on async_injector