yanpitangui/dotnet-api-boilerplate

Questionable clean architecture implementation

md-redwan-hossain opened this issue · 3 comments

Is your feature request related to a problem? Please describe.
Why EntityFramework is being added in the application layer? It must be in the infrastructure layer. application should not be concerned with your underlying database. Even DatabaseFacade is present in Microsoft.EntityFrameworkCore.Infrastructure namespace and you are using it in application layer.

using Boilerplate.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Boilerplate.Application.Common;

public interface IContext : IAsyncDisposable, IDisposable
{
    public DatabaseFacade Database { get; }
    
    public DbSet<Hero> Heroes { get; }
    
    public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default);
}

Describe alternatives you've considered
Move them to infrastructure, use repository and unit of work pattern.

Hi!
At first, this project was all about "clean architecture", even though I didn't mention it anywhere in the readme file. However, over time, it strayed away from it, as it introduces some redundancies like re-implementing the repository pattern, something that EF already does.
My plan is to move to something like a vertical slicing, modular monolith approach, but I haven't had time lately to migrate the project yet.
Hope I answered your question.
Thanks for contributing!

Yes vertical slicing will be a good choice. However, you can still use the implementation of EF's Repository pattern by utilizing generic repository, doing so, you don't need to drag EF in your application layer and code repetitions will be minimized. Here is an implementation

Yes, I know I can do it that way. As I said, that was how it was before I decided to remove it. The repository pattern is not the only way to reduce code repetitions.
If everything I'm doing is using EF behind the scenes, "tainting" my application layer is just simplifying things.
Hopefully in the near future I will be able to take another round in the modernization of this project, and get away completely from "clean arch".