-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Microsoft.EntityFrameworkCore dependency in Application layer #439
Comments
That's quite deliberate. I believe Jason covers why in his talk. That dependency is there because it's the database agnostic part of Entity Framework. The MS SQL server dependency is in Infrastructure. Sure, you can abstract it away behind a repository, but then you have a repository wrapping a repository ( |
Hi @ronnieholm, thank you for the reply and it makes perfect sense. If my application had a mix of EF and Dapper, would the recommended implementation be to abstract the Dapper bits behind a repository? Thanks again. |
It definitely breaks Dependency Rule from the original The Clean Architecture article by Robert C. Martin! |
@seoriy I totally agree with you on that one however, this is a choice for the architect to make and Jason has backed his choice in all his talks. Talking about the clean architecture book, Uncle bob also made an exception by saying
Jason said that's he is ok with coupling with EntityFramework since he used it for a very very long time. However, you can make the change easily in the template. It's not referenced everywhere, except for the DbSet dependency. |
I think he was talking about a bit other cases. I.e. if you use .NET Framework to write application, it's obvious, that you use BCL even to describe domain logic, so you may use System.Collections.Generic.List<> for domain logic, without treating it as a violation of The Dependency Rule. Same for IDisposable, LINQ, etc.
Also
It's only his personal choise. Someone else may want to use this template, but replacing EF Core with Dapper, for example... |
@seoriy Yes, the conclusion was for the chapter, the section above it was for setting the exception. And yes, everything is relative. As I said before, you can change this template to match your own definition. And again, this is not an absolute solution/template everything is flexible, you can build on it, change it, make it perfect for your own decisions. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Hi. I was curious if we should have a dependency on the database ORM within the Application layer? Specifically we're referencing Microsoft.EntityFrameworkCore in Application > TodoLists > Queries > GetTodos > GetTodosQuery.cs. Seems like this should be abstracted away from the business logic, maybe opting for Repository pattern to inject specific functionality.
private readonly ITodoRepository todosRepository;
public GetTodosQueryHandler(ITodosRepository todosRepository)
{
this.todosRepository = todosRepository;
}
public async Task<TodosVm> Handle(GetTodosQuery request, CancellationToken cancellationToken)
{
// ...
Lists = await todosRepository.GetTodoListsAsync(cancellationToken);
}
Appreciate any advice/guidance.
The text was updated successfully, but these errors were encountered: