IntentArchitect / Support

A repository dedicated to handling issues and support queries
3 stars 0 forks source link

IApplicationDbContext should always be exposed, even if using repositories #74

Closed shainegordon closed 9 months ago

shainegordon commented 9 months ago

What problem are you trying to solve?

Intent.Modules.EntityFrameworkCore will exclude the generation of IApplicationDbContext if the module Intent.Entities.Repositories.Api exists in the project.

Intent Architect should not be making this decision for the project.

Direct access to the DB context is extremely useful and necessary in some scenarios (e.g. Reports, Queries), without resorting to convoluted repository calls.

Describe the solution you'd like

ApplicationDbContext should always implement IApplicationDbContext

If teams do want to not allow any access, except via a repository, then making this a setting would also be suitable.

shainegordon commented 9 months ago

Here is a query that is currently NOT possible using repositories, due to CountAsync's design

_applicationContext.Projects.ByQueryState(QueryState.All).Count()

ByQueryState in this example is an extension method on IQueryable which can manipulate QueryFilters

In this case, updating CountAsync to support a linq expression is probably not the correct solution, and would not be needed if IApplicationDbContext existed

JonathanLydall commented 9 months ago

Hi @shainegordon,

We'll absolutely be adding this in the very near future, I actually started looking into it this morning. This will be optional based on an application setting, when enabled an interface will be available in the application layer exposing all the DbSets.

I'll update this issue once a pre-release module is available.

JonathanLydall commented 9 months ago

Hi @shainegordon, this is now available in version 4.4.14-pre.0 of the Intent.EntityFrameworkCore module. You will need to enable the Generate DbContext interface setting as it will not be generated by default.

Please don't hesitate to reach out should you have any comments or questions 🙂.

shainegordon commented 9 months ago

Hi @shainegordon, this is now available in version 4.4.14-pre.0 of the Intent.EntityFrameworkCore module. You will need to enable the Generate DbContext interface setting as it will not be generated by default.

Please don't hesitate to reach out should you have any comments or questions 🙂.

Great stuff, updated module and updated setting