Registering Collections in Autofac 2.1.10 RC

autofac

Solution

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());

Problem

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?

Original source