December 23, 2014

No service for type

Error:
An unhandled exception occurred while processing the request.
Exception: TODO: No service for type 'ABC.Services.XYZService' has been registered.
Microsoft.Framework.DependencyInjection.ServiceProviderExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)

Solution:
If you have a new Service in your ASP .Net vNext, you need to add below line in ConfigureServices(IServiceCollection services) function in Startup.cs for register it ;-)

services.AddTransient<XYZService>();

PS: At this time ASP .Net vNext, Visual Studio 2015 and MVC 6.0 are beta version.
Update 1: it could be solved with this services.AddScoped<XYZService>();

No comments: