39 lines
1.3 KiB
C#
39 lines
1.3 KiB
C#
namespace Jambo.Producer.Infrastructure.Modules
|
|
{
|
|
using Autofac;
|
|
using Autofac.Features.Variance;
|
|
using Jambo.Producer.Application.Commands.Blogs;
|
|
using MediatR;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
public class MediatRModule : Autofac.Module
|
|
{
|
|
protected override void Load(ContainerBuilder builder)
|
|
{
|
|
builder.RegisterSource(new ContravariantRegistrationSource());
|
|
|
|
builder
|
|
.RegisterType<Mediator>()
|
|
.As<IMediator>()
|
|
.InstancePerLifetimeScope();
|
|
|
|
builder
|
|
.Register<SingleInstanceFactory>(ctx => {
|
|
var c = ctx.Resolve<IComponentContext>();
|
|
return t => { object o; return c.TryResolve(t, out o) ? o : null; };
|
|
})
|
|
.InstancePerLifetimeScope();
|
|
|
|
builder
|
|
.Register<MultiInstanceFactory>(ctx => {
|
|
var c = ctx.Resolve<IComponentContext>();
|
|
return t => (IEnumerable<object>)c.Resolve(typeof(IEnumerable<>).MakeGenericType(t));
|
|
})
|
|
.InstancePerLifetimeScope();
|
|
|
|
builder.RegisterAssemblyTypes(typeof(CreateBlogCommand).GetTypeInfo().Assembly).AsImplementedInterfaces(); // via assembly scan
|
|
}
|
|
}
|
|
}
|