Consume entity repository directly from the application layer

Asked

Viewed 270 times

5

I have a scenario where I need to search for a list of Active Employees with Entity Framework and display them on the screen (I need to convert to Dtos before displaying - what I do through the Application layer).

For a DDD scenario (Domain-Driven Design) there are the layers of Applying, Domain and Infra... I am in doubt in this scope. The domain services are created when logic has importance to the domain, right ? So I could search this list directly from Application and Repository, without creating a service in the Domain ? Of course, looking for an asset list would be just a LINQ filter, I don’t know if I can consider that a business rule... Who can clarify me this doubt thank you.

1 answer

3


In DDD, the layer of Applying knows how to consume the objects of the Domain to meet the above layer requests (Interface); and in DDD repository is a type of domain object.

Now, if the Application layer consumes domain objects and if the repository is a domain object type, then there is no need to encapsulate the repository within a service so that it can be consumed by the application layer.

In DDD, the Application layer can rather consume repositories directly, without the need for these repositories to be encapsulated in another service.

Of course, if after obtaining the entities it is still necessary to execute any business logic, this business logic would indeed need to be in a service (which is a domain object type in DDD) or in itself entity.

Also note that the filter you will run on entities when consuming the repository directly from the application layer needs to be a filter with an API that speaks the language of business experts, since in DDD all domain layer code needs to speak this language.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.