I'm trying to implement passive attributes in an ASP.NET Web API. The filter I'm implementing has a dependency on a repository, which itself has a dependency on a custom DbContext. In the post it says that you can resolve the component with a DI container, but also that the code should be invoked from Application_Start. I'm not sure how to implement this, while taking advantage of the DI container's lifetime management capabilities (so that a new DbContext will be used per request). Would injecting an abstract factory be a good solution for this? or is there something simpler that I'm missing.
相关问题
- Entity Framework Code First Migration
- Entity Framework throws exception - Network Relate
- Register MicroServices in Azure Active Directory (
- PromptDialog Choice with List object Bot Framework
- Dotnet Core API - Get the URL of a controller meth
相关文章
-
EF6 DbSet
returns null in Moq - Entity Framework 4.3.1 failing to create (/open) a
- EF6 code first: How to load DbCompiledModel from E
- Why do I need a ToList() to avoid disposed context
- Code-First Add-Migration keeps adding the same col
- EF Codefirst validate unique property?
- EF Core 'another instance is already being tra
- Add XML documentation / comments to properties/fie
You can resolve this issue by sliding a Decoraptor in between the Filter and the Repository.
Not knowing a lot about your code, you should be able to define a Decoraptorepository using an Abstract Factory:
This enables your Filter to stay a Singleton, while the actual Repository is being created in a Transient manner.
If you need to dispose of objects too, please refer to the follow-up article on how to decommission Transient objects from within a Decoraptor.