You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, a service will be instantiated when it's requested. In some cases you need to create an instance after
booting the service container. For example a database connection or a background service that checks the connectivity.
To preload services you can use the @Preload annotation. This annotation is only available for singleton services.
Example:
@Service()
@Preload()
classMyService {
MyService() {
print('Service was created');
}
}
voidmain() {
ServiceContainer container;
container.boot(); // prints "Service was created"
container.resolve<MyService>(); // Nothing printed
}