Version 2.3 of Appeaser

Maintenance release adding IOptions<MediatorSettings> support

Posted by Carl Berg on Thu, Aug 1, 2019 | Tags appeaser, mediator

I have recently done a little maintenance update in Appeaser where i’ve added netstandard 2.0 compatibility for Appeaser and added support for IOptions<MediatorSettings> in Appeaser.Microsoft.DependencyInjection making use of the “options pattern”.

The latter of these updates enables you to configure mediator settings like this:

var serviceProvider = new ServiceCollection()
    .Configure<MediatorSettings>(o => o.AddRequestInterceptor<MyInterceptor>())
    .Configure<MediatorSettings>(o => o.AddRequestInterceptor<MyOtherInterceptor>())
    .AddAppeaser()
    .BuildServiceProvider();

…the benefit which might not be completely obvious compared to:

var serviceProvider = new ServiceCollection()
    .AddAppeaser(options => options
        .AddRequestInterceptor<MyInterceptor>()
        .AddRequestInterceptor<MyOtherInterceptor>())
    .BuildServiceProvider();

…however this enables you to make something like this:

public static IServiceCollection RegisterValidation(this IServiceCollection services)
{
    services.Configure<MvcOptions>(o => o.Filters.Add<HandleValidationExceptionActionFilter>());
    services.Configure<MediatorSettings>(o => o.AddRequestInterceptor<ValidationInterceptor>());
    return services;
}

… where an extension (that could be shared in a nuget package for instance) configures one or more options but doesn’t need direct access to the AddAppeaser(..) or AddMvc(..) methods, also the order these configurations are invoked doesn’t matter as creation of these options happen at a later stage.

Resources