I want to use autofac in my project for windows service but I get this error:
"The requested service 'InsideView.Business.Services.BusinessServiceFactory' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency."
My code:
var builder = new ContainerBuilder();
foreach (var type in typeof(IMyService).Assembly.GetTypes().Where(type => type.Name.EndsWith("Service") && type.IsClass))
{
var siblingInterface = type.GetInterfaces().First(i => i.Name == "I" + type.Name);
builder.RegisterType(type).Keyed(siblingInterface, typeof(IBusinessService)).InstancePerLifetimeScope();
}
builder.RegisterType<BusinessServiceFactory>()
.As<IBusinessServiceFactory>().InstancePerLifetimeScope();
IContainer container = builder.Build();
var businessFactory = container.Resolve<BusinessServiceFactory>()
Any ideas? Thanks
When you have registered the service as IBusinessServiceFactory
you must also resolve for IBusinessServiceFactory
, not the class type BusinessServiceFactory
as you are doing in the sample.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments