register<T> abstract method
- ServiceInitializer<
T> globalInitializer, - {String name,
- bool asSingleton = true}
This method shall be called to register a service with the injection context. It must only be called, after the startup has been called.
The initializer
is called when an instance of the service shall be
created. It must return the instance of the service. By passing a name
,
it is possible to register different services that implement the same
class. If the flag asSingleton
is true, the globalInitializer
is only called
once when resolving the service. The created service instance will be
cached. If the flag asSingleton
is false, the initializer
is called
every time when resolving the service.
Throws a InjectionContextNotInitialized exception, if the injection context is not started.
Throws a InjectionContextHasAlreadyService exception, if the service that shall be registered was already registered before.
Implementation
void register<T>(
ServiceInitializer<T> globalInitializer, {
String name,
bool asSingleton = true,
});