magnolia
magnolia

Reputation: 33

Domain Service that consumes external system

I am trying to implement an Employee Management System using DDD approach. The system is built using .Net Core. I have several Projects created for this system (UI, Application, Domain, Infrastructure). Now inside my Domain Layer, I have an Employee entity (that's the Aggregate root of Employee aggregate). The business requirement is that whenever an Employee is created, I need to do a Credit Check, and based on the result I am supposed to update a property called "IsCreditCheckDone" for the Employee entity. The Credit Check service is basically an external Rest Service. I am thinking to create an Interface called ICreditCheckService inside Domain.Services.Interfaces folder. I am thinking to do the implementation of ICreditCheckService in the Infrastructure layer inside the service folder. Also, ICreditCheckService will be injected into the Employee class and the Dependency will be mapped inside the Startup class of the UI project.

My question is, is it the correct approach to handle the Domain Service when it consumes the external systems? Or should it be done differently?

EMS.Domain

EMS.Infrastructure

Upvotes: 2

Views: 1253

Answers (1)

desertech
desertech

Reputation: 1029

In general, I think your design is good.

Two points, however:

  • Terminologically, The service that invokes an external api is not considered to be a domain service (a domain service runs logic that involves several entities). It is more like a repository.
  • Repository services should be injected not into entities but into application (use-case) services. For example, an application service invokes your credit-check service, then creates an employee entity passing to its ctor the boolean result.

Upvotes: 2

Related Questions