With some presumptions from how AutoFac works , i couldn't get my code working in my ASP.NET 5 app.I have integrated AutoFac as DI framework into my ASP.NET 5 app and everything works fine, and dependencies which i register before first call to Build method gets injected fine but when i try to register Modules from other assemblies referenced by main assembly i can't inject theme in controller anymore.
this is what i have tried:
ContainerBuilder builder = new ContainerBuilder();
builder.Register<MyService>().As<IMyService>();
builder.Build();
and after that i've create and registered a Module :
public class MyModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<SomeService>()
.As<ISomeService>()
.SingleInstance();
}
}
and within a manager class by injecting ILifetimeScope :
public class ManagerClass(){
private readonly ILifetimeScope _lifetimeScope;
public ManagerClass(ILifetimeScope lifetimeScope){
_lifetimeScope = lifetimeScope;
}
public void RegisterModules(){
_lifetimeScope.BeginLifetimeScope(builder =>
{
builder.RegisterAssemblyModules(blueprint.Assemblies.Select(b=>b.Assembly).ToArray());
});
}
}
i put a breakpoint on Load method of MyModule class and it gets hit, but when i try to inject ISomeService (registered by MyModule) i get ComponentNotRegisteredException exception.