IoC container doesn't always respect .InSingletonScope() #308
Replies: 2 comments 1 reply
-
As discussed on IRC, this is because the binding of You'll get the same with: Bind<Mercedes>().ToSelf().InSingletonScope();
Bind<ICar>().To<Mercedes>().InSingletonScope();
container.Get<ICar>() == container.Get<Mercedes>(); // False
This is also how Autofac does it: https://dotnetfiddle.net/taPUZZ and https://dotnetfiddle.net/hPVA8e. |
Beta Was this translation helpful? Give feedback.
-
Could I suggest introducing new API to make it behave as discussed? It would just be an addition to the existing IoC without changing existing behaviour. |
Beta Was this translation helpful? Give feedback.
-
Take the following
ConfigureIoC()
code:When retrieving them as follows:
We end up with two distinct instances of
Mercedes
despite the fact thatMercedes
was configured in singleton scope.Beta Was this translation helpful? Give feedback.
All reactions