Skip to content

RFC: De-Couple data access from EF #84

Closed
@jaredcnance

Description

@jaredcnance

Problem

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

  1. 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);
    }
}
  1. Refactor the context graph:
  • Rename ContextGraphBuilder to EntityContextGraphBuilder, since it uses the EF DbContext.
  • Can ContextGraph be used without the DbContext generic? If not, perform rename Entity...
  • Define API to either inject custom IContextGraph implementations or an API to build a generalized context graph
  1. Refactor service extensions or add methods for using the new APIs defined by (2)

Considerations

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest for comments. These issues have major impact on the direction of the library.enhancementextensibility

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions