diff --git a/src/Application/DependencyInjection.cs b/src/Application/DependencyInjection.cs index 469289d24..d1c72a17d 100644 --- a/src/Application/DependencyInjection.cs +++ b/src/Application/DependencyInjection.cs @@ -35,8 +35,8 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection options.UseReduxDevTools(); }); services.AddLazyCache(); - services.AddScoped(); - services.AddScoped(sp => { + services.AddSingleton(); + services.AddSingleton(sp => { var service = sp.GetRequiredService(); service.Initialize(); return service; diff --git a/src/Application/Services/Picklist/PicklistService.cs b/src/Application/Services/Picklist/PicklistService.cs index c436a47f4..ae213ce69 100644 --- a/src/Application/Services/Picklist/PicklistService.cs +++ b/src/Application/Services/Picklist/PicklistService.cs @@ -1,5 +1,6 @@ using CleanArchitecture.Blazor.Application.Features.KeyValues.Caching; using CleanArchitecture.Blazor.Application.Features.KeyValues.DTOs; +using Microsoft.Extensions.DependencyInjection; namespace CleanArchitecture.Blazor.Application.Services.Picklist; @@ -11,10 +12,12 @@ public class PicklistService : IPicklistService public PicklistService( IAppCache cache, - IApplicationDbContext context, IMapper mapper) + IServiceScopeFactory scopeFactory, + IMapper mapper) { _cache = cache; - _context = context; + var scope = scopeFactory.CreateScope(); + _context = scope.ServiceProvider.GetRequiredService(); _mapper = mapper; }