Skip to content

Latest commit

 

History

History
165 lines (127 loc) · 3.05 KB

File metadata and controls

165 lines (127 loc) · 3.05 KB

Migration



From Version 4 to Version 5

Version 5:

class RootFactory extends DependencyFactory<RootDependency> {
  @override
  Future<RootDependency> create() async {
    return RootDependency(
      apiService: await ApiService().init(),
    );
  }
}
class RootDependency extends DependencyContainer {
  final AuthRepository authRepository;

  ModuleDependency({required super.authRepository});

  void dispose() {
    // authRepository.dispose();
  }
}
DependencyScope<RootDependency, RootFactory>(
    factory: RootFactory(),
    placeholder: const Center(child: CircularProgressIndicator()),
    builder: (context) => const YourWidget(),
);
final rootDependency = await RootFactory().create();

DependencyProvider<RootDependency>(
    dependency: rootDependency,
    child: const YourWidget(),
);

Version 4:

DependencyScope<RootDependency>(
    dependency: RootDependency(),
    placeholder: const Center(child: CircularProgressIndicator()),
    builder: (context) => const YourWidget(),
);
class ModuleDependency extends DependencyContainer<RootDependency> {
  late final AuthRepository authRepository;

  ModuleDependency({required super.parent});

  @override
  Future<void> init() async {
    authRepository = AuthRepository(
      apiService: parent.apiService,
    );
  }

  void dispose() {
    // authRepository.dispose();
  }
}
DependencyProvider.of<ModuleDependency>(context);
DependencyProvider.maybeOf<ModuleDependency>(context);
// or
context.depend<ModuleDependency>();
context.dependMaybe<ModuleDependency>();

From Version 3 to Version 4

Version 3:

InjectionScope<RootLibrary>(
  library: RootLibrary(),
  placeholder: const Center(child: CircularProgressIndicator()),
  child: const YourWidget(),
);
class RootInjection extends Injection {
  late final ApiService apiService;

  @override
  Future<void> init() async {
    apiService = await ApiService().init();
  }
}
InjectionScope.of<ModuleInjection>(context);

Version 4:

DependencyScope<RootDependency>(
    dependency: RootDependency(),
    placeholder: const Center(child: CircularProgressIndicator()),
    builder: (context) => const YourWidget(),
);
class ModuleDependency extends DependencyContainer<RootDependency> {
  late final AuthRepository authRepository;

  ModuleDependency({required super.parent});

  @override
  Future<void> init() async {
    authRepository = AuthRepository(
      apiService: parent.apiService,
    );
  }

  void dispose() {
    // authRepository.dispose();
  }
}
DependencyProvider.of<ModuleDependency>(context);
DependencyProvider.maybeOf<ModuleDependency>(context);
// or
context.depend<ModuleDependency>();
context.dependMaybe<ModuleDependency>();

Key Differences:

  • InjectionScopeDependencyScope
  • InjectionDependencyContainer
  • InjectionScopeDependencyProvider