开发者

In DDD with Entity Framework where should the Context Interface live?

开发者 https://www.devze.com 2023-03-29 07:45 出处:网络
I\'m using Entity Framework in my DDD Application where I have Domain, Infra and UI Layers. My Context Interface is here:

I'm using Entity Framework in my DDD Application where I have Domain, Infra and UI Layers.

My Context Interface is here:

public interface IDbContext
{
    IDbSet<TEntity> Set<TEntity>() where TEntity : class;
    DbEntityEntry Entry<TEntity>(TEntity entity) w开发者_如何学Pythonhere TEntity : class;

    void SaveChanges();
}

My Context Interface actually lives in the Domain Layer.

How are you seeing, my context has a dependency of Entity Framework because my base repository and my entire app use that.

Where should I put this Interface? Move that to Infra? I want to isolate my Domain of any technologies.


You should move the interface to ifra layer. Also you should ensure that this interface or any type implementing the interface is not directly used in any other layer because once you access DbSet or DbEntityEntry elsewhere you have a dependency.


I think you should forget about directly using the IDbContext inteface. A better solution, IMHO, would be to define Repository interfaces on you domain, without any reference to the Entity Framework and, in the infrastructure layer, you would define the implementations for that repository.

Any query to models would be done through the repositories which, in turn, returns a model or an IEnumrable of models.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号