Skip to content

Instantly share code, notes, and snippets.

@thiagomajesk
thiagomajesk / AutoFacModule.cs
Last active August 30, 2023 16:47
Generic Handlers & Commands for MediatR (+ AutoFac config)
public class GenericHandlersModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<CreateCommandHandler<Foo, CreateFooCommand>>().As<IRequestHandler<CreateFooCommand, bool>>();
builder.RegisterType<DeleteCommandHandler<Foo, DeleteFooCommand>>().As<IRequestHandler<DeleteFooCommand, bool>>();
builder.RegisterType<ListQueryHandler<Foo, ListFooQuery>>().As<IRequestHandler<ListFooQuery, IEnumerable<Foo>>>();
builder.RegisterType<UpdateCommandHandler<Foo, UpdateFooCommand>>().As<IRequestHandler<UpdateFooCommand, bool>>();
}
}