Castle.Windsor.Extensions.DependencyInjection: Transient services are not disposed.
See original GitHub issue- Have a controller dependent on a transient service.
Component.For<ITransientService>().ImplementedBy<TransientService>().LifestyleTransient(),
or with MSInjection
services.AddTransient<ITransientService, TransientService>();
- When using MS injection the service is disposed right after the controller is disposed.
- When using Windsor the service is disposed after application shutdown.
Project to test out this scenario: https://github.com/AntonioDrusin/WindsorNetCore31Tester
It is inconsistent that the behavior of transient services is different between using MSInjection and CastleWindsor. The behavior is also inconsistent with how Transient services work in Windsor.
The planned use for this extension is to be able to use our current windsor registrations in Net Core 3.0. With this difference in behavior (transient services not being freeed until shutdown) that won’t be possible.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:29 (27 by maintainers)
Top Results From Across the Web
Ext.DI: dependencies of component with lifestyle pooled ...
We use Castle Windsor as a DI container in a .NET Core 3.1 project. In the project, we have a component A with...
Read more >WindsorContainer not releasing transient components ...
Since WindsorAdapter implements IRelease, HelloService will be tried to be disposed by windsor, but since it has not been created by Windsor, ...
Read more >When are .NET Core dependency injected instances ...
1 Answer. The resolved objects have the same life-time/dispose cycle as their container, that's unless you manually dispose the transient ...
Read more >Dependency injection guidelines - .NET
The framework does not dispose of the services automatically. The developer is responsible for disposing the services. IDisposable guidance for ...
Read more >New dependency injection features in .NET 6
Handling IAsyncDisposable services with IServiceScope ... Use DisposeAsync to dispose the container. at Microsoft.Extensions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The solution was very simple. We had to give windsor control over the creation of the controller. https://andrewlock.net/controller-activation-and-dependency-injection-in-asp-net-core-mvc/#the-servicebasedcontrolleractivator
Simply calling:
fixed my issue.
I think the only thing needed for this issue to go away is to document this extension. I think that the LifestyleNetTransient still has value if you do not want to use windsor to resolve the controller.
That’s also my understanding of a transient lifestyle and probably that of most developers out there.
If windsor should be used as implementation of microsoft extensions dependency injection, it has to adopt the imposed principles, at least in my opinion. To have a separate “net-transient” lifestyle could be confusing and should be avoided.