Per request scopes in e.g. Autofac will eat resources
See original GitHub issueSample here: https://gist.github.com/danielwertheim/887868c17ab8cd67be44
Kind of followed your sample code… Probably have missed something. And yes, I know I could inject Func<SomeDependency>
instead and have the handler resolve and dispose…
But how do I acomplish per-routed message scoped handlers? If not possible with MediatR, perhaps state that clearly in the sample?
Issue Analytics
- State:
- Created 8 years ago
- Comments:23 (14 by maintainers)
Top Results From Across the Web
How do I work with per-request lifetime scope?
Per -request lifetime makes use of tagged lifetime scopes and the “Instance Per Matching Lifetime Scope” mechanism. The request scope is tagged with...
Read more >Controlling Scope and Lifetime - Autofac's documentation!
Effectively, a lifetime scope equates with a unit of work in your application. A unit of work might begin a lifetime scope at...
Read more >Why does Autofac's implicit relationship type for dynamic ...
They can keep channels open and eat up resources if you don't do ... Your MVC controller gets resolved from the per-request lifetime...
Read more >Dependency injection guidelines - .NET
Discover effective dependency injection guidelines and best practices for developing .NET apps. Deepen your understanding of inversion of ...
Read more >Comparing ASP.NET Core IoC container service lifetimes ...
Instance per request builds on top of instance per matching lifetime scope by providing a well-known lifetime scope tag, a registration ...
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
@kappy I see!
I wonder if this can work with Owin? The challenge with Owin is that there is not really a static way of getting the current request context. I’ll have to think about it 😄
Just resolve the stuff you need from a lifetime scope (as shown in the blog post mentioned)? Make sure you dispose it when you’re finished. Or just dispose the container when you’re done with it.
I’m not sure what you’re talking about here. What func?
I don’t think anyone here are experts on all the containers in the samples that have been contributed to this repo, and by all means, they could absolutely have bugs. I guess it’s generally expected to know how the container you’re using works. That should probably be a requirement anyway - whether you’re using MediatR or not 😉 If you’re having trouble wiring up the container properly, maybe it’s best to just go “pure DI”-style? 😄
If you’re looking to learn more about Autofac and its lifetime scoping and transient tracking, I suggest you read NIck’s blog, specifically An Autofac lifetime primer. There are also some good resources on Controlling Scope and Lifetime in the Autofac docs, specifically the bits about Disposal.