From Version 4 to 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 (),
);
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
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);
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 >();
InjectionScope → DependencyScope
Injection → DependencyContainer
InjectionScope → DependencyProvider