C
C#8mo ago
Ares

✅ Dependency Injection Error?

I am injecting it in Program.cs:
builder.Services.AddIdentityCore<IdentityUser>()
.AddRoles<IdentityRole>()
.AddTokenProvider<DataProtectorTokenProvider<IdentityUser>>("RealTimePolls")
.AddEntityFrameworkStores<RealTimePollsAuthDbContext>()
.AddDefaultTokenProviders();
}
builder.Services.AddIdentityCore<IdentityUser>()
.AddRoles<IdentityRole>()
.AddTokenProvider<DataProtectorTokenProvider<IdentityUser>>("RealTimePolls")
.AddEntityFrameworkStores<RealTimePollsAuthDbContext>()
.AddDefaultTokenProviders();
}
so I dont understand why when I inject it into my repository:
{
public class SQLAuthRepository : IAuthRepository
{
private readonly RealTimePollsDbContext dbContext;
private readonly UserManager<IdentityUser> userManager;

public SQLAuthRepository(RealTimePollsDbContext dbContext
, UserManager<IdentityUser> userManager
)
{
this.dbContext = dbContext;
this.userManager = userManager;
}
{
public class SQLAuthRepository : IAuthRepository
{
private readonly RealTimePollsDbContext dbContext;
private readonly UserManager<IdentityUser> userManager;

public SQLAuthRepository(RealTimePollsDbContext dbContext
, UserManager<IdentityUser> userManager
)
{
this.dbContext = dbContext;
this.userManager = userManager;
}
it is giving me the error:
[15:20:20 ERR] 0f01858e-8fd6-442c-a045-21bee09ade58 : Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
at lambda_method206(Closure, IServiceProvider, Object[])
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
[15:20:20 ERR] 0f01858e-8fd6-442c-a045-21bee09ade58 : Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Controllers.AuthController'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
at lambda_method206(Closure, IServiceProvider, Object[])
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
1 Reply
Ares
AresOP8mo ago
Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: RealTimePolls.Repositories.IAuthRepository Lifetime: Scoped ImplementationType: RealTimePolls.Repositories.SQLAuthRepository': Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Repositories.SQLAuthRepository'.)
Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: RealTimePolls.Repositories.IAuthRepository Lifetime: Scoped ImplementationType: RealTimePolls.Repositories.SQLAuthRepository': Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' while attempting to activate 'RealTimePolls.Repositories.SQLAuthRepository'.)
nvm there was a typo in my porgram.cs
Want results from more Discord servers?
Add your server