Integration Event Converter¶
The integration event converter is a tool for converting domain events into integration events.
With the integration event converter, you can decouple the sending of integration events from the business logic in other domain event handlers.
Define Integration Event Converter¶
- Install the nuget package
NetCorePal.Extensions.DistributedTransactions.Abstractions
dotnet add package NetCorePal.Extensions.DistributedTransactions.Abstractions
-
Define the integration event converter, which requires:
-
Inherit the
NetCorePal.Extensions.DistributedTransactions.IIntegrationEventConverter
interface; - Implement the Convert method of the IIntegrationEventConverter interface, which takes a domain event IDomainEvent as a parameter and returns an integration event IntegrationEvent.
Here is an example:
// Define integration event converter
using NetCorePal.Web.Application.IntegrationConvert;
namespace YourNamespace;
public class OrderCreatedIntegrationEventConverter
: IIntegrationEventConverter<OrderCreatedDomainEvent, OrderCreatedIntegrationEvent>
{
public OrderCreatedIntegrationEvent Convert(OrderCreatedDomainEvent domainEvent)
{
return new OrderCreatedIntegrationEvent(domainEvent.Order.Id);
}
}
- The framework comes with a code generator to automatically generate integration event handlers.
Here is an example of an integration event handler generated by the code generator:
```csharp
//
}
}