Domain Export
Sometimes when you are working on a multi-domain service or your domain has been thought as a library instead of a service, the domain business logic can be exported.
This is possible thanks to the class called domain.Service
as part of the domain package.
Remember, Domain Service implements a Facade pattern, so we need to add the method definition and the use case bind to execute.
Binding entity (service) with the Domain Service
Torpedo adds out of the box a bind between the domain service and the entity service. So, each time that you need to call
an entity service method, like Create
or Read
or even your own entity method, an instance of it will be available via
the domain.Service
class.
For instance, following the Blog App exampel, if your entity is named post
the entry point method will be domain.Service.Post()
Binding use case with the Domain Service
Registering a use case as part of the domain service should be easier, based on the Blog App example:
Remember that our case is
Name: Onboarding
Description As a system a new user must be added if the email has not been registered previously.
lets adding a method named RegisterNewUser
to our domain.Service
in order to call the use case implementation.
At the domain service file we should add the code like below:
domain/service.go
- Adding the use case method at domain service definition
- This is a reference to the Use Case instance
- Adding the use case reference as parameter in the Domain Service constructor
- Binding the use case reference
- Method implementation that calls the referenced use case logic.
This is the Facade pattern implementation.