Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can infrastructure services return domain entities in Uncle Bob's The Clean Architecture?

Consider:

The Use Case layer defines an interface

public interface IGeocoder
{
    Coordinate GetCoordinate(Address address);
}

Coordinate and Address are value objects defined in the domain layer (i.e. entities layer in Uncle Bob jargon). Obviously the use case (interactor) constructs the Address and passes it to the IGeocoder, expecting a Coordinate to be returned.

Would this break any Clean Architecture rules? Should I be instead passing DTOs through the interface, so that the actual implementation of the service is not responsible for generating the domain entities? Or is this fine?

Note that I don't see any difference between this and a repository (entity gateway), whose interface would also be defined in the Use Case layer but implemented in the surrounding Interface Adapters layer:

public interface IRestaurantRepository
{
   // ...
}
like image 365
Jordan Walker Avatar asked Nov 15 '25 18:11

Jordan Walker


1 Answers

Who is owning the implementation of the infrastructure service? Is it the same team? Then it should be fine to handle it similar to repositories; return domain entities directly. Is it owned by different team? Then creating a boundary and passing dedicated DTOs might be beneficial as it creates less coupling.

like image 103
plainionist Avatar answered Nov 18 '25 08:11

plainionist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!