Register collections in Autofac 2.1.10 RC

I am updating the code from Autofac 1.4 to 2.1.10 Release Candidate.

My module previously did the registration as follows:

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

Now RegisterCollection has no overload parameters. I do not need to give him a name. Assuming this is fine, just type null , my code looks like this: 2.1:

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

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

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

I tried to insert the name of the collection instead of null, just in case, and this did not affect.

What is the correct way to register collections in 2.1?

+7
autofac
source share
1 answer

As I understand it, you just register the IExceptionHandler type IExceptionHandler , and then when you request an IEnumerable<IExceptionHandler> , Autofac 2 just takes care of everything for you.

On 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()); 
+6
source share

All Articles