Order
Example implementation of Model ‘Order’ for use in App Service.
The default structure of the “Application” project starts with a folder called “EventHandlers” and a “EventHandlers.cs” file for logging and mapping the “Domain Event” with the “Event Handler”.
When triggering a “Domain Event” in the business rule, an “Event Handler” will be triggered with code that interacts with the technology layer.
In addition, there is a folder for the inclusion of Interfaces, which in this context includes only the “IExtension.cs” file, responsible for enabling project customizations through Adapter Extensions.
The Application.csproj
file contains the default project settings and you don’t need to include any additional dependencies. According to the architecture strategy, this project has a reference to the project Domain
to connect to the project’s business rules.
The parameter Version
should be updated by the DevOps strategy with the ID of the new version of the microservice application.
The reference related to Devprime Stack
should be the same in all projects, and you can update it automatically by running the command dp stack
, provided by the Devprime CLI and run in the project’s main folder.
|
|
One of the important pillars offered by the Devprime platform is the standardization of software development and at this point in the Application project it is already possible to follow some strategies for organizing folders and files that allow you to scale the development teams in a standardized way.
The example below depicts an example of including an “Application Services” that receives an event in a MongoDB API and repository using the State Adapter. This procedure can be done manually by implementing each folder and file, or by using the dp init
offered by the Devprime CLI that parses business rules in Domain
and makes the implementations.
Important Items:
The Application project works as a transport layer in this strategy where the software architecture is decoupled and the connection happens through a dependency inversion (DI) strategy.
#1 - Implementing the Order.cs / Item.cs
models
In the structure of the Devprime platform, the folder for the implementation of the “Models” for the “Application Services” is located in “Core > Application > Services” and are used for standardization of parameters and mappings.
A common example found in the implementations of these Models is the relationship with business objects present in the Domain project, as represented in the code block below. Using this approach, the “Domain” does not know the “Application”.
|
|
For more details, explore the two models below:
#2 - Implementing the Interface IOrderService.cs
In the Devprime platform structure, the folder for implementing the “Application Services” interfaces is located in the “Application” project under “Core > Application > Interfaces > Services”. In the example below, we are demonstrating the “Add/Update/Delete/Get/GetAll” methods.
|
|
#3 - Implementing Application Service OrderService.cs
In the Devprime platform structure, the folder for the implementation of “Application Services” in the Application project is under “Core > Application > Services”. In the example below, we’re reproducing an example implementation of the “Add” method where it takes the command, converts it to the domain model. When using the Dp.Attach(order)
statement, it adds the object to the “Devprime Pipeline” and then run the Add method.
|
|
#4 - Implement Handlers CreateOrderEventHandler.cs
and OrderCreatedEventHandler.cs
In the structure of the Devprime platform, to maintain decoupling, the business rules do not communicate directly with the technologies. Instead, “Handlers” are implemented in “Core > Application > EventHandlers”, which are used to enable code that reacts to a business fact (“Domain Event”), e.g. Dp.ProcessEvent<bool>(new CreateOrder())
, emitted within the Domain.
Example Handler implementation: CreateOrderEventHandler.
The sample code demonstrates the persistence of an Aggregate in a database by interacting with the Adapter of State. This technological implementation in the Application is isolated from the Domain.
|
|
Example Handler implementation: OrderCreatedEventHandler.
The sample code enables the emitting of an event by allowing the communication of a business fact externally to the microservice, through interaction with the Stream, which seamlessly integrates with RabbitMQ, Kafka, and other platforms. This technological implementation in the Application is isolated from the Domain.
|
|
#5 - Implementing models used in Event Handlers
In the Devprime platform structure, the folder for the implementation of the “Models” for the “EventHandlers” is located in the “Core > Application > EventHandlers > Order > Model” and are used in communication with the Adapters.
|
|
|
|
#6 - Registering Handles for Domain Events EventHandler.cs
In the Application layer in “Core / Application / EventHandlers” a HUB will be available to register the Handles that will be intercepting the domain events and establishing a relationship between them.
|
|
#7 - Implementing Inferface IOrderState.cs
The application layer also plays an important role in registering interfaces for interaction with other Adapters, such as State. The interfaces are organized in the “Core > Application > Interfaces > Adapters” folder structure, and according to this context, we will use a specific folder for the Adapter.
|
|
Example implementation of Model ‘Order’ for use in App Service.
Example implementation of Model ‘Item’ for use in App Service.