The requested service has not been registered ! AutoFac Dependency Injection

With the statement:

builder.RegisterType<ProductService>().As<IProductService>();

Told Autofac whenever somebody tries to resolve an IProductService give them an ProductService

So you need to resolve the IProductService and to the ProductService:

using (var container = builder.Build())
{
    container.Resolve<IProductService>().DoSomething();
}

Or if you want to keep the Resolve<ProductService> register it with AsSelf:

builder.RegisterType<ProductService>().AsSelf();

Leave a Comment