Order
Example of Model ‘Order’ deployment for use in App Service.
The default structure of the “Application” project starts with a folder called “EventHandlers” and a “EventHandlers.cs” file for registering 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 the code that interacts with the technology layer.
In addition, there is a folder for the inclusion of the Interfaces, which in this context includes only the “IExtension.cs” file, responsible for enabling customizations of the project through the Adapter Extensions.
The Application.csproj
file contains the default settings for the project and does not need to include any additional dependencies. According to the architectural strategy, this project has a reference to the project Domain
to connect to the project’s business rules.
The Version
parameter 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 dp stack
, provided by the Devprime CLI and executed in the main project 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 development teams in a standardized way.
The example below depicts an example of including an “Application Services” that receives an event in an API and a MongoDB 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 the business rules in the Domain
and does 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 “IOrderService.cs” Interface
In the Devprime framework, 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/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 are reproducing an example of an implementation of the “Add” method where it receives the command, converts it to the domain model. Using the Dp.Attach(order)
statement, it adds the object to the “Devprime Pipeline” and then run the Add method.
|
|
#4 - Implementation of the “CreateOrderEventHandler.cs” and “OrderCreatedEventHandler.cs” Handlers
In the structure of the Devprime platform, to maintain decoupling, business rules do not communicate directly with technologies. Instead, “Handlers” are implemented in “Core > Application > EventHandlers”, which are used to enable code that reacts to a business fact (“Domain Event”), for example, Dp.ProcessEvent<bool>(new CreateOrder())
, emitted within the Domain.
Handler implementation example: CreateOrderEventHandler.
The sample code demonstrates the persistence of an Aggregate in a database by interacting with the Adapter of State. This technological implementation in Application is isolated from Domain.
|
|
Example Handler implementation: OrderCreatedEventHandler.
The sample code enables the emission of an event by allowing the communication of a business fact externally to the microservice, through interaction with the Stream, which integrates seamlessly with RabbitMQ, Kafka, and other platforms. This technological implementation in Application is isolated from Domain.
|
|
#5 - Implementing models used in Event Handlers
In the Devprime framework, the folder for implementing the Models for the EventHandlers is located in the Core > Application > EventHandlers > Order > Model and are used to communicate with the Adapters.
|
|
|
|
#6 - Registering the Handles for “EventHandler.cs” Domain Events
In the Application layer in “Core / Application / EventHandlers” will be available a HUB for registration of 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 by registering interfaces for interaction with other Adapters, such as the 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 of Model ‘Order’ deployment for use in App Service.
Example of deploying the Model ‘Item’ for use in App Service.