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, if you expose multiple services, like IMyFirstService, IMySecondService and MyClass, from a MyClass class (which is registered as singleton), then you resolve/inject the the same service with different references, you get different instances.
If you always resolve with IMyFirstService you always get the same object. However, when you resolve with IMySecondService then you get a second instance.
This is not a good thing for singletons since you expect a real single instance.
This change makes it always returning the same instance even if you resolve it with different type references.
While this is a breaking change, it should not effect any application. Even it fixes some problems like #3777
Also, it is similar with scoped lifetime. From now, you get the exact same instance in the same scope for scoped registered services.
The text was updated successfully, but these errors were encountered:
hikalkan
changed the title
Singleton services exposing multiple services should return the same instance
Singleton & scoped services exposing multiple services should return the same instance
May 6, 2020
Currently, if you expose multiple services, like
IMyFirstService
,IMySecondService
andMyClass
, from aMyClass
class (which is registered as singleton), then you resolve/inject the the same service with different references, you get different instances.If you always resolve with
IMyFirstService
you always get the same object. However, when you resolve withIMySecondService
then you get a second instance.This is not a good thing for singletons since you expect a real single instance.
This change makes it always returning the same instance even if you resolve it with different type references.
While this is a breaking change, it should not effect any application. Even it fixes some problems like #3777
Also, it is similar with scoped lifetime. From now, you get the exact same instance in the same scope for scoped registered services.
The text was updated successfully, but these errors were encountered: