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

Externally provided singleton instances are disposed on container disposal #538

Open
timbussmann opened this issue Aug 27, 2020 · 0 comments

Comments

@timbussmann
Copy link
Contributor

Using the Microsoft.Extensions.DependencyInjection integration, when registering an existing object instance as a singleton, it's dispose method is also invoked when the IServiceProvider is disposed although the instance has been created by the user and not by the container itself. The Microsoft default implementation does not dispose instances that have been registered this way but it doesn't seem to be a part of the "specs".

repro:

var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(new MySingleton());
var serviceProvider = serviceCollection.CreateLightInjectServiceProvider(new ContainerOptions().WithMicrosoftSettings());

var singleton = serviceProvider .GetService<MySingleton>();
(sp as IDisposable).Dispose(); // Dispose of MySingleton is called

Are there any plans to align the disposal behavior with Microsoft's default container implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant