I register services with the following code (used Autofac MVC integration package):
// IoC
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
builder.RegisterModelBinders(Assembly.GetExecutingAssembly()).PropertiesAutowired();
builder.RegisterModelBinderProvider();
builder.RegisterFilterProvider();
builder.RegisterAssemblyTypes(myAssembly)
.AssignableTo(typeof(IMyInterface))
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
Now I want to inject a collection of IMyInterface
implementations:
public MyClass(Lazy<IEnumerable<IMyInterface>>> myInterfaces)
{
}
The problem is that myInterfaces.Value
contains two different instances of the same implementation. I mean:
public MyServ: IMyInterface
{
}
There are two instances of MyServ
in the myInterfaces.Value
collection.
I have version 4 of Autofac, downloaded in May 2014. Everything worked fine until the last AutoFac update (via nuget). Has anything changed in Autofac so my snippet does not work? What I am doing wrong?