-
Notifications
You must be signed in to change notification settings - Fork 56
Eager vs. Lazy Instantiation
Back to Advanced IoC Configuration
By default, dependency providers are created lazily. This means that the dependency will not be created by Deft JS until another object is created which specifies that dependency as an injection.
In cases where lazy instantiation is not desired, you can set up a dependency provider to be created immediately upon application startup by using the eager
configuration:
Deft.Injector.configure({
notificationService: {
className: "MyApp.service.NotificationService",
eager: true
}
});
NOTE: Only singleton dependency providers can be eagerly instantiated. This means that specifying
singleton: false
andeager: true
for a dependency provider won't work. The reason may be obvious: Deft JS can't do anything with a prototype object that is eagerly created, since by definition each injection of a prototype dependency must be a new instance!