Czołem koledzy programiści!
Mam solucję podzieloną na kilka projektów. Tam gdzie to potrzebne, dodaję klasę dziedziczącą po Autofac.Module. Chciałbym załadować wszystkie moduły do projektu startowego (Web) bez dodawania referencji do wszystkich pozostałych projektów.
Kod konfiguracji, który oczywiście startuję w Global.asax
private static void SetAutofacContainer()
{
var builder = new ContainerBuilder();
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
builder.RegisterAssemblyModules(loadedAssemblies);
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
Przykładowy moduł w osobnym projekcie
public class ApplicationModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterAssemblyTypes(ThisAssembly).Where(t => t.Name.EndsWith("Service")).AsImplementedInterfaces()
.AsSelf()
.InstancePerLifetimeScope();
}
}
Niestety otrzymuję błąd
`Inner Exception 1:
DependencyResolutionException: An error occurred during the activation of a particular registration. See the inner exception for details. Registration: Activator = CatalogController (ReflectionActivator), Services = [MySolution.Web.Controllers.CatalogController], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScopeInner Exception 2:
DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'MySolution.Web.Controllers.CatalogController' can be invoked with the available services and parameters:
Cannot resolve parameter 'MySolution.Contracts.Interfaces.ICatalogViewModelService catalogViewModelService' of constructor 'Void .ctor(MySolution.Contracts.Interfaces.ICatalogViewModelService)'.`
Co czynię źle i czy mógłby ktoś naprowadzić mnie, jak to wszystko powiązać?
Pozdrawiam,
KK