Skip to content

Activation Module

The activation module allows to configure certain entities to be activated or deactivated according to business necessities.

Integration

Depending on the ActivationModule will automatically register all required dependencies for filtering out inactive entities (as well as the ones required to opt out from this behavior). An entity can be made deactivatable by implementing the corresponding interface

C#
1
2
3
4
5
6
7
public class MyModule : SuiteModule
{
    public override void SetupModule(IModuleBuilder builder)
    {
        builder.DependsOn<ActivationModule>();
    }
}
C#
1
2
3
4
5
6
public class Reason : IDeactivatableEntity
{
    public Guid CorrelationId { get; set; }

    public bool IsActive { get; set; } = true;
}

Important

Remember to initialize IsActive field to true unless you want all new instances of your entity to be created as inactive ones.

The handling of this field is mostly up to the implementor to decide, we only expose a utility method SetActiveStatus(bool isActive). The module will automatically decorate the newly added field in your entity's class mapping.

Filtering

Inactive entities will be filtered out by default. Of course, activation filters out entities via a global filter specification, which are not applied when querying via FindByIdAsync method(or any of its derivatives).

This behavior can be overridden if needed by injecting the IActivationContextManager.

C#
public class MyService : IService
{
    private readonly IActivationContextManager activationContextManager;
    private readonly IReadOnlyRepository<Guid, Entity> repository;

    public MyService(
        IActivationContextManager activationContextManager,
        IReadOnlyRepository<Guid, Entity> repository)
    {
        this.activationContextManager = activationContextManager;
        this.repository = repository;

    }

    public async Task DoSomething()
    {
        await activationContextManager.WithActivationFilterDisabledAsync(
            () => await this.repository.AllAsync();
        );
    }
}