English 中文(简体)
Registering Collections in Autofac 2.1.10 RC
原标题:
  • 时间:2010-02-24 21:16:04
  •  标签:
  • autofac

I am upgrading code from Autofac 1.4 to 2.1.10 Release Candidate.

My module previously performed registration like this:

builder.RegisterCollection<IExceptionHandler>()
                .As<IEnumerable<IExceptionHandler>>()
                .FactoryScoped();
builder.Register<AspNetExceptionHandler>()
                .As<IExceptionHandler>()
                .MemberOf<IEnumerable<IExceptionHandler>>()
                .FactoryScoped();

Now, RegisterCollection has no parameterless overload. I don t care about assigning it a name. Assuming it s OK to just pass in null, my code looks like this in 2.1:

builder.RegisterCollection<IExceptionHandler>(null)
                .As<IEnumerable<IExceptionHandler>>()
                .InstancePerDependency();
builder.RegisterType<AspNetExceptionHandler>()
                .As<IExceptionHandler>()
                .MemberOf<IEnumerable<IExceptionHandler>>(null)
                .InstancePerDependency();

However, when I compile, I get the following error regarding .MemberOf:

Using the generic method Autofac.RegistrationExtensions.MemberOf(Autofac.Builder.RegistrationBuilder, string) requires 3 type arguments

I tried putting in a collection name instead of null, just in case, and that had no effect.

What s the proper way to register collections in 2.1?

最佳回答

As I understand it, you just register a bunch of IExceptionHandler types, and then when you request an IEnumerable<IExceptionHandler> Autofac 2 will just take care of everything for you.

From the NewInV2 page:

builder.RegisterType<A1>().As<IA>();
builder.RegisterType<A2>().As<IA>();

var container = builder.Build();

// Contains an instance of both A1 and A2
Assert.AreEqual(2, container.Resolve<IEnumerable<IA>>().Count());
问题回答

暂无回答




相关问题
Registering Collections in Autofac 2.1.10 RC

I am upgrading code from Autofac 1.4 to 2.1.10 Release Candidate. My module previously performed registration like this: builder.RegisterCollection<IExceptionHandler>() .As<...

How to carry out custom initialisation with autofac

I m adding autofac to an existing project and some of the service implementations require their Initialize method to be called and passed configuration information. Currently I m using the code: ...

Autofac doesn t like MVC Source

I added the ASP.NET MVC 2 RC2 source code to my solution (using these instructions: http://blog.stevensanderson.com/2009/02/03/using-the-aspnet-mvc-source-code-to-debug-your-app/), but now it won t ...

IOC/Autofac container

I am currently using Autofac, but am open to commentary regarding other IOC containers as well. I would prefer a solution using Autofac if possible. I am also somewhat new to IOC so I may be grossly ...

Dependency Injection for Presenter

I have a Presenter that takes a Service and a View Contract as parameters in its constructor: public FooPresenter : IFooPresenter { private IFooView view; private readonly IFooService service;...

热门标签