-
I'm sure there's a good reason for this, but I was wondering why the choice to use ContainerControlledLifetimeManager for registering singletons over SingletonLifetimeManager when using Unity. From my (admittedly limited) understating. the ContainerControlled version only registers the object as singleton against the current container. So if I registered a singleton in multiple child containers, they would effectively be scoped to that container. Whereas if it were registered using SingletonLifetimeManager you could register once in a child container, and that registration would be registered to the parent container. I can think of instances where both options would be useful. For example I may want to use a ChildContainer in a plugin to make sure that only the plugin has access to most of its functionality. But then I may also want to register a singleton with the root container so the main application could make use of it. I know I could technically register it to the root from the plugin also. But perhaps adding a RegisterSingletonToRoot set of extensions using the SingletonLifetimeManager might be a good addition without breaking existing functionality. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Unless you can provide an example that shows an actual issue we don't have plans to make a change here. I've also already validated that this works as expected. var container = Setup.CreateContainer();
Setup.Registry.RegisterSingleton<IServiceA, ServiceA>();
var resolved = container.Resolve<IServiceA>();
Assert.Same(resolved, container.Resolve<IServiceA>());
var scope = container.CreateScope();
Assert.Same(resolved, scope.Resolve<IServiceA>()); |
Beta Was this translation helpful? Give feedback.
Unless you can provide an example that shows an actual issue we don't have plans to make a change here. I've also already validated that this works as expected.