One service for each entity?

前端 未结 2 1975
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-11 06:55

Again - i\'m confused about DDD things :)

I have architeture (I\'m still working on it) that in short hand looks like that:

DataLayer:
 EntityDao -> I         


        
2条回答
  •  自闭症患者
    2021-02-11 07:05

    My thoughts:

    1. Services provide upper level interface for business logic. Generally, you should hide your domain level implementation details (which is lower) behind it's methods, basically commands or queries. A good way of thinking could be to name your service methods after use cases or user stories. And you shouldn't provide more functionality that required by service clients (UI).

    2a. If your UI needs all data from entities of some type then yes, otherwise no. And FindAll() is hardly a use case.

    2b. You should use Repositories from your Services, that's actually the only place where you should use it.

    3 see 2b.

    4 Yes. You should leave interfaces for repositories in your Domain, but implementation should be in Data Access. Then you can glue everything with some IoC container. Could be like this:

    //in domain
    public interface IUserRepository {
        User GetById(Guid id);
    }
    //in data access
    public class UserRepository : IUserRepository
    {
        public UserRepsitory(/* some orm specific dependencies */) { }
        public User GetById(Guid id) { /* implementation */ }
    }
    

提交回复
热议问题