Closed
Description
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
- 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
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 Hard dependency to MVC setup #71)?