Skip to content

services.mapping.setup

Brian Greco edited this page Apr 5, 2023 · 1 revision

IMAGE Mapping Plugin Setup

The mapping plug-in provides structure for mapping source to target objects. This is a common occurrence at the public API boundary where internal aggregates and domain entities are mapped to publicly exposed resource models.

The NetFusion.Mapping plug-in contains an implementation to help structure code responsible for mapping objects. Instead of having this mapping code contained within services or helper classes, the goal is to make the mapping code easy to access without having to add additional code distracting from the core business logic.


IMAGEThe implementation does not depend on any open-source mapping libraries and allows the application code to use their mapping library of choice. It should also be noted that the base implementation does not attempt to map the object's state and is only responsible for loading and resolving the mapping strategies responsible for performing the mappings.


Example Solution

The mapping topic assume an example microservice was creating using the NetFusion microservice template. The example microservice can be created by completing the following steps.

If the netfusion-microservice template is not installed execute the following:

dotnet new install NetFusion.Templates

Next, create the example solution:

cd mkdir Examples.Mapping
cd Examples.Mapping
dotnet new netfusion-microservice --port 5010

The generated microservice is configured to use Serilog and SEQ. A SEQ server instance can be executed within Docker by running the following:

cd ./seq
docker-compose up -d

The SEQ log web interface can be viewed here: http://localhost:8051

Registering Mapping Plugin

The mapping implementation is contained within the following NuGet package: NetFusion.Services.Mapping

Add a reference to the NetFusion.Services.Mapping NuGet package to the Infra project by completing the following:

dotnet add ./src/Components/Examples.Mapping.Infra package NetFusion.Services.Mapping

Next, add the following line of code to add the plugin to the composite-container:

// Add Plugins to the Composite-Container:
    builder.Services.CompositeContainer(builder.Configuration, new SerilogExtendedLogger())
        .AddSettings()
        
        .AddMapping() // <-- Add this line

        .AddPlugin<InfraPlugin>()
        .AddPlugin<AppPlugin>()
        .AddPlugin<DomainPlugin>()
        .AddPlugin<WebApiPlugin>()
        .Compose();

Message Router

Clone this wiki locally