Skip to content

Asset

For services like Service Order, or Inspections, we need a way of abstracting from the actual "things" or "places" we are performing maintenance against, or inspections.

Asset is an abstract concept it may be a Soda Machine, a Stateroom, a Restaurant, a Corridor, etc.

Currently, the Suite includes Locations and Components as independent concepts. An Asset is a materialized view of those.

Asset Client Module

An AssetClientModule is provided in order to allow other services to integrate with this concept. The module includes the Asset entity, it's EF Core mappings, and is kept in sync with Components and Locations.

How to use it

The main idea behind the AssetClientModule is that you create your own entity (i.e ServiceOrder) and can have relations to an entity Asset which is provided by the module.

The DB structure is included as your own service's migrations, and it is handled as another regular entity. The only difference is that we can share the class and it's mapping so that you don't need to write them!

Defining an entity with an asset

First we need to reference the AssetClientModule's Abstraction assembly from our Domain layer.

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

This will allow us to create an entity which has an Asset:

C#
using ITsynch.Suite.Assets.Domain;

namespace ITsynch.Suite.ServiceOrders.Domain
{
    public class ServiceOrder : BaseSagaStateMachineInstance
    {
        // [..]
        public Asset Asset { get; private set; } = null!;
    }
}

We then need to add an EntityTypeConfiguration for this entity on our Persistence layer as usual:

C#
namespace ITsynch.Suite.ServiceOrders.Persistence
{
    internal class ServiceOrderConfiguration
        : IEntityTypeConfiguration<ServiceOrdersDbContext, ServiceOrder>
    {
        public void Configure(EntityTypeBuilder<ServiceOrder> builder)
        {
            // [..]
            builder.HasOne(x => x.Asset)
                .WithMany()
                .IsRequired()
                .OnDelete(DeleteBehavior.NoAction);
        }
    }
}

After doing that, we must reference and configure the AssetClientModule on our Application Module before we can generate migrations.

Configuring the Application Module

First we have to include the AssetClientModule reference in your Application layer csproj:

XML
<ProjectReference Include="$(ServicesPath)Assets/ITsynch.Suite.AssetsClientModule/ITsynch.Suite.AssetsClientModule.csproj" />

Afterwards, we need to DependOn and configure our AssetClientModule in our service's Application Module:

C#
public class MyServiceApplicationModule : SuiteAspNetApplicationModule {

    public override void SetupModule(IModuleBuilder builder)
    {
        builder.DependsOn<AssetClientModule, AssetClientModuleOptions>(
            opts =>
            {
                // We need to configure the DbContext where we want the Asset
                // entity added. This is usually "The DbContext" that you have.
                opts.SetDbContext<ServiceOrdersDbContext>();
            });
    }
}

We can now generate migrations for our service as usual, and we should see the one to one relation we just added, and the table for Assets being created.

You can then use the entities as usual.