RFC: De-Couple data access from EF
See original GitHub issueProblem
Currently, the controller leans on IEntityRepository
directly which is tightly coupled to IQueryable
. However, this doesn’t make much sense for ORMs, like Dapper, that do not use IQueryable
. Also, it is entirely possible that resources may be retrieved from non SQL storage solutions, such as another HTTP API or RPC.
Tightly Coupled Areas:
Proposed Solution
- Extract controller logic into
IResourceService
. Reduces controller methods to something like the following. Would allow any intermediate service to perform the data access.
public class JsonApiController<T, TId>
: JsonApiControllerMixin where T : class, IIdentifiable<TId>
{
private readonly IResourceService<T, TId> _service;
public JsonApiController(IResourceService<T, TId> resourceService)
{
_service = resourceService;
}
[HttpGet]
public virtual async Task<IActionResult> GetAsync()
{
var entities = await _service.GetAsync();
return Ok(entities);
}
}
- Refactor the context graph:
- Rename
ContextGraphBuilder
toEntityContextGraphBuilder
, since it uses the EFDbContext
. - Can
ContextGraph
<T> be used without theDbContext
generic? If not, perform renameEntity...
- Define API to either inject custom
IContextGraph
implementations or an API to build a generalized context graph
- Refactor service extensions or add methods for using the new APIs defined by (2)
Considerations
- Need to take a closer look at json:api operations and how this would fit in.
- Since this may introduce a variety of breaking changes, perhaps we should consider further de-coupling from the MVC middleware in this solution as well (see discussion in #71)?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Using Entity Framework generated classes in Business ...
Without the decoupling, the EF objects can become deeply embedded in the BLL and even presentation layers, requiring a huge refactoring.
Read more >EF Core: Effectively decouple the data and domain model
In this post, I'll be expressing my views on the clear separation of persistence related models and business models and look into how...
Read more >RFC 2764 - A Framework for IP Based Virtual Private ...
RFC 2764 IP Based Virtual Private Networks February 2000 2.1.2 Data Security In general customers using VPNs require some form of data security....
Read more >Implementing the infrastructure persistence layer with ...
Entity Framework (EF) Core is a lightweight, extensible, and cross-platform version of the popular Entity Framework data access technology. It ...
Read more >c# - Where should helper classes/methods for transforming ...
I have created a Business Logic Layer (BLL) and a Data Access Layer (DAL) (in folders/namespaces in the same project, not as class...
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
Sounds good. In order to decouple it completely, we must get rid of the DbContext generic type. So rather something like:
=> Everything inside the DbContext can be added and further more custom ressources not bound to any DbContext. For backwards compatibility, we can still leave the currently public methods as is and call this builder internally.
Been getting familiar with the project and that’s one of the first things that came to mind. Can I use this with a custom business/data layer? That would be really nice.