Skip to content

Integration

Configuring a message for replication is pretty straightforward. First things first, lets add required references.

In our contracts project:

XML
<ProjectReference Include="$(ServicesPath)Replication\ITsynch.Suite.Replication.Abstractions\ITsynch.Suite.Replication.Abstractions.csproj" />

By convention, and since we want to replicate facts and not intents, we use events and not commands whenever it is possible. Exceptions may happen, of course, where we want to replicate a command instead, but these cases should be treated carefully.

Lets add the required interface to our event.

C#
1
2
3
4
5
6
public record SpareUpdated : IReplicableMessage
{
    public Guid CorrelationId { get; set; }

    public Guid SharingLevelId { get; set; }
}

Now we need to configure a replication module where we can expose this message. If no such module is already present for the bounded context you are working on, we need to create a new one inside dotnet/src/services/Replication/ReplicableMessages/

You can do so by running the provided suite template and specifying your bounded context name for the project:

Bash
1
2
3
cd dotnet
./activate.sh
dotnet new replication -B Spares

And add a reference to your contracts layer.

XML
<ProjectReference Include="$(ServicesPath)Spares/ITsynch.Suite.Spares.Application.Contracts/ITsynch.Suite.Spares.Application.Contracts.csproj">

Now we can expose our message from inside ReplicationModule options:

C#
public class ReplicationSparesModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);

        builder.DependsOn<ReplicationModule, ReplicationModuleOptions>(opts =>
        {
            opts.AddReplicableMessage<SpareUpdated>();
        });
    }
}

The engine needs to be aware of the newly added message so it can respond as expected when a Replicated{SpareUpdated} message is received. In order to do so, just depend on your new module from the ReplicableMessages module under Replication/ReplicableMessages/ITsynch.Suite.Replication.ReplicableMessages

C#
1
2
3
4
5
6
7
8
public class ReplicableMessagesModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        builder.DependsOn<ReplicationSparesModule>();
    }
}

Your application module needs some tuning aswell: add references to ReplicationClientModule and your new ReplicationSparesModule.

XML
<ProjectReference Include="$(ServicesPath)Replication\ITsynch.Suite.Replication.ClientModule\ITsynch.Suite.Replication.ClientModule.csproj" />
<ProjectReference Include="$(ServicesPath)Replication\ReplicableMessages\ITsynch.Suite.Replication.Spares\ITsynch.Suite.Replication.Spares.csproj" />
C#
public class SparesApplicationModule : SuiteAspNetApplicationModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        // Code ommited for brevity.

        builder.DependsOn<ReplicationClientModule>();
        builder.DependsOn<ReplicationSparesModule>();
    }
}

The client module will set things up such that when a SpareUpdated is published, a Replicated{SpareUpdated} is published aswell, which will then be handled by the replication engine.