Skip to content

Unhandled exception. System.AggregateException: Some services are not able to be constructed #119

Description

@0llirocks

.NET Version: 10.0
SecurityKey Version: 4.0.0

I created a custom validator like in the documentation and added the following config to program.cs

builder.Services.AddScoped<IApiUserRepository, ApiUserRepository>();
builder.Services.AddSecurityKey<DatabaseSecurityKeyValidator>();

My implementation is almost 100% like in the example except it is called ApiUser instead of ApiKey. Once I run my program I get the following:

Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: AspNetCore.SecurityKey.ISecurityKeyValidator Lifetime: Singleton ImplementationType: Services.DatabaseSecurityKeyValidator': Cannot consume scoped service 'Interfaces.IApiUserRepository' from singleton 'AspNetCore.SecurityKey.ISecurityKeyValidator'.) (Error while validating the service descriptor 'ServiceType: AspNetCore.SecurityKey.SecurityKeyAuthorizationFilter Lifetime: Singleton ImplementationType: AspNetCore.SecurityKey.SecurityKeyAuthorizationFilter': Cannot consume scoped service 'Interfaces.IApiUserRepository' from singleton 'AspNetCore.SecurityKey.ISecurityKeyValidator'.) (Error while validating the service descriptor 'ServiceType: AspNetCore.SecurityKey.SecurityKeyAuthenticationHandler Lifetime: Transient ImplementationType: AspNetCore.SecurityKey.SecurityKeyAuthenticationHandler': Cannot consume scoped service 'Interfaces.IApiUserRepository' from singleton 'AspNetCore.SecurityKey.ISecurityKeyValidator'.)

Am I missing something?

BTW when I use AddSecurityKey without my own validator everything works as expected.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions