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
Let's assume I have a Customer component - this is the parent component. I also have CustomerList and CustomerDetails components - these are child components and they are displayed inside Customer component. All three components have to share some data and some business logic including Web API calls. I want to encapsulate this in CustomerService. Currently the only reasonable choice is to register CustomerService as Singleton and then inject it into all three Customer* components.
It's OK but below is another scenario where Singleton is not enough.
I have CustomerComparer component and I want to display two different customers side by side. To do this I want to use two Customer components. Of course they cannot work with the same instance of CustomerService. The only solution I see here is to register CustomerService as Scoped (which is currently equivalent to Singleton). Scoped should work as follows:
service injected into the first component in hierarchy should work as Transient,
all child components should get the same service instance as parent component.
With the above functionality I will be able to display two Customer components at the same time.
We would probably handle this by a mechanism like context in #5455 rather than DI. There are often situations where you'd want to share state with a subtree without having to register things in DI, and once we enable that, you wouldn't need the DI approach. Hope that makes sense!
Let's assume I have a Customer component - this is the parent component. I also have CustomerList and CustomerDetails components - these are child components and they are displayed inside Customer component. All three components have to share some data and some business logic including Web API calls. I want to encapsulate this in CustomerService. Currently the only reasonable choice is to register CustomerService as Singleton and then inject it into all three Customer* components.
It's OK but below is another scenario where Singleton is not enough.
I have CustomerComparer component and I want to display two different customers side by side. To do this I want to use two Customer components. Of course they cannot work with the same instance of CustomerService. The only solution I see here is to register CustomerService as Scoped (which is currently equivalent to Singleton). Scoped should work as follows:
With the above functionality I will be able to display two Customer components at the same time.
Look at #5496 also.
The text was updated successfully, but these errors were encountered: