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
Currently, the RegisterLazy method in our dependency injection container actually instantiates the service at the time of registration rather than doing so lazily at the time of first use. This behavior is counterintuitive given the name of the method and does not align with the expected pattern of lazy instantiation.
Proposal
I propose we implement a true lazy instantiation pattern by introducing a LazyActivator class which will defer the creation of the service until it is first requested. This change would ensure that the RegisterLazy method only instantiates the service when it is actually needed, potentially improving performance, especially during startup.
In this case, there are options - to make the activator so that it creates a new instance each time, or to “cache” it. The first option is simpler and limits liability, and caching will be provided by decoration using CachingActivator
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Summary
Currently, the
RegisterLazy
method in our dependency injection container actually instantiates the service at the time of registration rather than doing so lazily at the time of first use. This behavior is counterintuitive given the name of the method and does not align with the expected pattern of lazy instantiation.Proposal
I propose we implement a true lazy instantiation pattern by introducing a
LazyActivator
class which will defer the creation of the service until it is first requested. This change would ensure that theRegisterLazy
method only instantiates the service when it is actually needed, potentially improving performance, especially during startup.In this case, there are options - to make the activator so that it creates a new instance each time, or to “cache” it. The first option is simpler and limits liability, and caching will be provided by decoration using
CachingActivator
Additionally, the RegisterLazy method would be modified to use this new LazyActivator.
Benefits
Discussion Points
Are there any scenarios where the current eager instantiation behavior of RegisterLazy is actually desirable?
Beta Was this translation helpful? Give feedback.
All reactions