Skip to content

Contribution

Services can be configured either as providers or requestors by depending on the client module and calling the corresponding configuration methods.

XML
<ProjectReference Include="$(ServicesPath)DataManagement/ITsynch.Suite.DataManagement.ClientModule/ITsynch.Suite.DataManagement.ClientModule.csproj" />
C#
public class EquipmentsApplicationModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        builder.DependsOn<DataManagementClientModule, DataManagementClientModuleOptions>(
            opts =>
            {
            });
    }
}

For data gathering (meaning your service requires some external data) call RequireEntity as follows:

C#
public class EquipmentsApplicationModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        builder.DependsOn<DataManagementClientModule, DataManagementClientModuleOptions>(
            opts =>
            {
                opts.RequireEntity<AddressView>(AddressesConstants.AddressWellKnownName)
            });
    }
}

Lets take a deeper look here:

  • AddressView is the local representation of the entity you are requesting and has no real value for this configuration besides identifying the entity.
  • We are passing a well-known name as the configuration parameter. This is actually important: it is the key that universally identifies the entity you are requesting (the actual entity, not your local projection or view) and is crucial for being able to detect where to ask for the data.

Warning

Always use the entity well-known name when configuring requirements, for this example it would be Addresses/Address.

For data provisioning, call ExposeEntity method from the configuration callback:

C#
public class EquipmentsApplicationModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        builder.DependsOn<DataManagementClientModule, DataManagementClientModuleOptions>(
            opts =>
            {
                opts.ExposeEntity<Equipment, EquipmentUpdated>()
            });
    }
}

The configuration has two generic parameters:

  • The EntityType being exposed.
  • The EventType which will be used to transport the data.

Important

An AutoMapper profile from EntityType to EventType is required for the feature to properly map the data being sent.

Depending on the context we are working on, we might find ourselves in the situation where we need to provide hundreds, if not thousands of rows of data. For such cases, we can further configure the module to use a batching strategy, which is encouraged in order to improve performance where its necessary.

C#
public class EquipmentsApplicationModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        builder.DependsOn<DataManagementClientModule, DataManagementClientModuleOptions>(
            opts =>
            {
                opts.ExposeEntity<Equipment, EquipmentUpdated>()
                    .UseBatching(
                        take: 1000,
                        batchSize: 100,
                        delaySeconds: 15);
            });
    }
}
  • The total amount of rows we expect to take.
  • The batchSize to be used for each iteration (this directly affects the query to be executed against the storage).
  • A delay, expressed in seconds, that will be awaited after each iteration. This might be useful to relieve the broker and let messages be consumed at a slower pace.

Override defaults

The data provisioning process has a central dependency over a IEntityDataProvider service, which is responsible for querying and mapping the data to the specified record.

A default implementation for this service is provided by the module, which should cover most use cases, but if you find yourself in need of doing something special in there you can override it with your custom implementation.

C#
public class EquipmentsApplicationModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        base.SetupModule(builder);
        builder.DependsOn<DataManagementClientModule, DataManagementClientModuleOptions>(
            opts =>
            {
                opts.ExposeEntity<Equipment, EquipmentUpdated>()
                    .UseProvider<MyCustomEquipmentsDataProvider>();
            });
    }
}