From e4a9057e46d830ead876e28bb1c7f255533e3e96 Mon Sep 17 00:00:00 2001 From: Phil Schneider Date: Mon, 4 Dec 2023 15:10:03 +0100 Subject: [PATCH] fix(identity): change identity service to scoped (#370) Refs: CPLP-3102 --- .../ProcessIdentityServiceCollectionExtensions.cs | 4 ++-- .../ClaimsIdentityServiceCollectionExtensions.cs | 2 +- .../PortalBackend.DBAccess/Identities/IdentityService.cs | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/framework/Framework.ProcessIdentity/DependencyInjection/ProcessIdentityServiceCollectionExtensions.cs b/src/framework/Framework.ProcessIdentity/DependencyInjection/ProcessIdentityServiceCollectionExtensions.cs index dec08791ba..a57992518a 100644 --- a/src/framework/Framework.ProcessIdentity/DependencyInjection/ProcessIdentityServiceCollectionExtensions.cs +++ b/src/framework/Framework.ProcessIdentity/DependencyInjection/ProcessIdentityServiceCollectionExtensions.cs @@ -44,7 +44,7 @@ public static IServiceCollection AddConfigurationIdentityService(this IServiceCo .ValidateOnStart(); return services - .AddTransient() - .AddTransient(); + .AddScoped() + .AddScoped(); } } diff --git a/src/framework/Framework.Web/ClaimsIdentityServiceCollectionExtensions.cs b/src/framework/Framework.Web/ClaimsIdentityServiceCollectionExtensions.cs index 04a56f7628..0f9d87ee9b 100644 --- a/src/framework/Framework.Web/ClaimsIdentityServiceCollectionExtensions.cs +++ b/src/framework/Framework.Web/ClaimsIdentityServiceCollectionExtensions.cs @@ -29,6 +29,6 @@ public static IServiceCollection AddClaimsIdentityIdDetermination(this IServiceC { return services .AddScoped() - .AddTransient(); + .AddScoped(); } } diff --git a/src/portalbackend/PortalBackend.DBAccess/Identities/IdentityService.cs b/src/portalbackend/PortalBackend.DBAccess/Identities/IdentityService.cs index bf781c06c1..3ac25a1dab 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Identities/IdentityService.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Identities/IdentityService.cs @@ -37,7 +37,9 @@ public IdentityService(IPortalRepositories portalRepositories, IIdentityIdDeterm /// public async ValueTask GetIdentityData() => - _identityData ??= await _identityRepository.GetActiveIdentityDataByIdentityId(IdentityId).ConfigureAwait(false) ?? throw new ConflictException($"Identity {_identityIdDetermination.IdentityId} could not be found"); + _identityData ?? (_identityData = + await _identityRepository.GetActiveIdentityDataByIdentityId(IdentityId).ConfigureAwait(false) ?? + throw new ConflictException($"Identity {_identityIdDetermination.IdentityId} could not be found")); public IdentityData IdentityData => _identityData ?? throw new UnexpectedConditionException("identityData should never be null here (endpoint must be annotated with an identity policy / as an alternative GetIdentityData should be used)");