Autofac等效于此特定Ninject绑定

时间:2014-01-29 19:04:53

标签: c# c#-4.0 dependency-injection ninject autofac

在Ninject中我有:

 kernel.Bind<IDomainEventHandler<WinnerSelectedEvent>>()
        .To<WinnerSelectedHandler>();

Autofac与此相当的是什么?

1 个答案:

答案 0 :(得分:2)

Autofac相当于Ninject的:

kernel.Bind<Type>().To<Impl>();

时:

builder.RegisterType<Impl>().As<Type>();

所以相应的应该是:

var builder = new ContainerBuilder();
builder.RegisterType<WinnerSelectedHandler>().As<IDomainEventHandler<WinnerSelectedEvent>>();
var container = builder.Build();