Open
Description
Which Umbraco version are you using?
v15.1.2
Bug summary
Copied from: https://forum.umbraco.com/t/di-issues-with-documenteventauthorizer/1814
We have Umbraco v15.1.2 running fine for a large project I am working on. When I try to upgrade Umbraco to v15.2+ or v15.3, I get the exception below, running the project. The issue is due to the introduction of DocumentEventAuthorizer as a singleton, which relies on IAuthorizationService which is scoped and not a singleton.
Specifics
System.AggregateException HResult=0x80131500
Message=Some services are not able to be constructed Source=Microsoft.Extensions.DependencyInjection StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
at ClientProject.Program.<Main>d__0.MoveNext() in C:\projects\Clients\ClientProject.Web\Program.cs:line 23
at ClientProject.Web.Program.<Main>(String[] args)
This exception was originally thrown at this call stack:
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.VisitCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.CallSiteValidatorState) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.VisitConstructor(Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.CallSiteValidatorState) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor<TArgument, TResult>.VisitCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite, TArgument) Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.VisitCallSite(Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteValidator.CallSiteValidatorState) Microsoft.Extensions.DependencyInjection.ServiceProvider.ValidateService(Microsoft.Extensions.DependencyInjection.ServiceDescriptor) Inner Exception 1: InvalidOperationException: Error while validating the service descriptor 'ServiceType: Umbraco.Cms.Api.Management.ServerEvents.Authorizers.DocumentEventAuthorizer Lifetime: Singleton ImplementationType: Umbraco.Cms.Api.Management.ServerEvents.Authorizers.DocumentEventAuthorizer': Cannot consume scoped service 'Microsoft.AspNetCore.Authorization.IAuthorizationService' from singleton 'Umbraco.Cms.Api.Management.ServerEvents.Authorizers.DocumentEventAuthorizer'. Inner Exception 2: InvalidOperationException: Cannot consume scoped service 'Microsoft.AspNetCore.Authorization.IAuthorizationService' from singleton 'Umbraco.Cms.Api.Management.ServerEvents.Authorizers.DocumentEventAuthorizer'.
Steps to reproduce
Steps to reproduce: Modify the Startup.cs, adding the following:
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseDefaultServiceProvider(
(context, options) =>
{
options.ValidateOnBuild = true;
options.ValidateScopes = true;
});
Alternatively, set "ASPNETCORE_ENVIRONMENT": "Development"
in the launchSettings.json.
Expected result / actual result
No response