Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singleton & scoped services exposing multiple services should return the same instance #3837

Closed
hikalkan opened this issue May 5, 2020 · 0 comments

Comments

@hikalkan
Copy link
Member

hikalkan commented May 5, 2020

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.

@hikalkan hikalkan added this to the 2.7 milestone May 5, 2020
@hikalkan hikalkan self-assigned this May 5, 2020
@hikalkan 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant