سؤال

Help to understand deeper, there are contract / interface for repository

public interface ICoolRepository
{
    Entity GetById(int id);
}

where shoul it be declared in domain, infrastracture or app module?

Can repository interface be used in entities like that:

public class User
{
...
  public DoStuff(ICoolRepository repo)
  {
    //here goes using cool repository
  }
...
}

where can it be used with no problem? please, give reasones for that

هل كانت مفيدة؟

المحلول

The interface should be defined in Domain Model, as it is a part of Ubiquitous Language (it expresses, what is an aggregate and what is not, it expresses the ways the aggregates should be looked for which relates directly or indirectly to some use cases). The implementation of the repository should go to Infrastructure as it contains DAL/ORM references.

It is rather uncommon or wrong to use a repository in entities, but your question is too generic to give you any meaningful answer.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top