ASP.NET Core DI with Repository pattern (DAL, Service, Controller)

175 Views Asked by At
public void ConfigureServices(IServiceCollection services)
{       
    services.AddTransient<IUserService, UserService>();
    services.AddControllersWithViews();
    services.AddOptions();
    services.AddMvc();
}

An error occurred while starting the application. AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: DataServiceLayer.OperationInfrastructure.IUserService Lifetime: Transient ImplementationType: DataServiceLayer.OperationService.UserService': Unable to resolve service for type 'DataAccessLayer.Operation.IUsersRepository' while attempting to activate 'DataServiceLayer.OperationService.UserService'.)

1

There are 1 best solutions below

0
Ali Alizade On

You must add to Startup.cs file your Repository lifecycle too.

For example:

services.AddTransient<IUserRepository, UsersRepository>();