diff --git a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs index 05531096d4..00f7f5da23 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.Web.Theming/PageToolbars/PageToolbarManager.cs @@ -3,16 +3,17 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.DependencyInjection; namespace Volo.Abp.AspNetCore.Components.Web.Theming.PageToolbars; public class PageToolbarManager : IPageToolbarManager, ITransientDependency { - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } public PageToolbarManager( - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) { ServiceScopeFactory = serviceScopeFactory; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs index b795c62c39..ec27b8087c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared/PageToolbars/PageToolbarManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; @@ -10,11 +11,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.PageToolbars; public class PageToolbarManager : IPageToolbarManager, ITransientDependency { protected AbpPageToolbarOptions Options { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } public PageToolbarManager( IOptions options, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) { Options = options.Value; ServiceScopeFactory = serviceScopeFactory; diff --git a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs b/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs deleted file mode 100644 index a7f00f7451..0000000000 --- a/framework/src/Volo.Abp.AspNetCore/Volo/Abp/AspNetCore/DependencyInjection/HttpContextServiceScopeFactory.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.DependencyInjection; - -namespace Volo.Abp.AspNetCore.DependencyInjection; - -[ExposeServices( - typeof(IHybridServiceScopeFactory), - typeof(HttpContextServiceScopeFactory) - )] -[Dependency(ReplaceServices = true)] -public class HttpContextServiceScopeFactory : IHybridServiceScopeFactory, ITransientDependency -{ - protected IHttpContextAccessor HttpContextAccessor { get; } - - protected IServiceScopeFactory ServiceScopeFactory { get; } - - public HttpContextServiceScopeFactory( - IHttpContextAccessor httpContextAccessor, - IServiceScopeFactory serviceScopeFactory) - { - HttpContextAccessor = httpContextAccessor; - ServiceScopeFactory = serviceScopeFactory; - } - - public virtual IServiceScope CreateScope() - { - var httpContext = HttpContextAccessor.HttpContext; - if (httpContext == null) - { - return ServiceScopeFactory.CreateScope(); - } - - return new NonDisposedHttpContextServiceScope(httpContext.RequestServices); - } - - protected class NonDisposedHttpContextServiceScope : IServiceScope - { - public IServiceProvider ServiceProvider { get; } - - public NonDisposedHttpContextServiceScope(IServiceProvider serviceProvider) - { - ServiceProvider = serviceProvider; - } - - public void Dispose() - { - - } - } -} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs index bf8e2e3028..7874fddb86 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/GenerateProxyCommand.cs @@ -1,4 +1,5 @@ using System.Text; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Cli.ServiceProxying; using Volo.Abp.DependencyInjection; @@ -13,7 +14,7 @@ public class GenerateProxyCommand : ProxyCommandBase public GenerateProxyCommand( IOptions serviceProxyOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) : base(serviceProxyOptions, serviceScopeFactory) { } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs index 22311bb986..67c61b2a28 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs @@ -2,6 +2,7 @@ using System.IO; using System.Text; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; @@ -19,11 +20,11 @@ public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependenc protected AbpCliServiceProxyOptions ServiceProxyOptions { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } public ProxyCommandBase( IOptions serviceProxyOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) { ServiceScopeFactory = serviceScopeFactory; ServiceProxyOptions = serviceProxyOptions.Value; diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs index d89c19c892..3372584f1a 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/RemoveProxyCommand.cs @@ -1,4 +1,5 @@ using System.Text; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Cli.ServiceProxying; using Volo.Abp.DependencyInjection; @@ -13,7 +14,7 @@ public class RemoveProxyCommand : ProxyCommandBase public RemoveProxyCommand( IOptions serviceProxyOptions, - IHybridServiceScopeFactory serviceScopeFactory) + IServiceScopeFactory serviceScopeFactory) : base(serviceProxyOptions, serviceScopeFactory) { } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs deleted file mode 100644 index befcf7951e..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/DefaultServiceScopeFactory.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace Volo.Abp.DependencyInjection; - -[ExposeServices( - typeof(IHybridServiceScopeFactory), - typeof(DefaultServiceScopeFactory) - )] -public class DefaultServiceScopeFactory : IHybridServiceScopeFactory, ITransientDependency -{ - protected IServiceScopeFactory Factory { get; } - - public DefaultServiceScopeFactory(IServiceScopeFactory factory) - { - Factory = factory; - } - - public IServiceScope CreateScope() - { - return Factory.CreateScope(); - } -} diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs b/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs deleted file mode 100644 index 62c3707352..0000000000 --- a/framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/IHybridServiceScopeFactory.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; - -namespace Volo.Abp.DependencyInjection; - -public interface IHybridServiceScopeFactory : IServiceScopeFactory -{ - -} diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs index d325708175..aa933c6e09 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Volo.Abp.Authorization.Permissions; using Volo.Abp.DependencyInjection; @@ -13,11 +14,11 @@ namespace Volo.Abp.UI.Navigation; public class MenuManager : IMenuManager, ITransientDependency { protected AbpNavigationOptions Options { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } protected ISimpleStateCheckerManager SimpleStateCheckerManager { get; } public MenuManager( IOptions options, - IHybridServiceScopeFactory serviceScopeFactory, + IServiceScopeFactory serviceScopeFactory, ISimpleStateCheckerManager simpleStateCheckerManager) { Options = options.Value; diff --git a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs b/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs deleted file mode 100644 index 6a3f059ba8..0000000000 --- a/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DependencyInjection/HybridServiceScopeFactory_Tests.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; -using Shouldly; -using Volo.Abp.Modularity; -using Xunit; - -namespace Volo.Abp.DependencyInjection; - -public class HybridServiceScopeFactory_Tests -{ - [Fact] - public async Task Should_Use_Default_ServiceScopeFactory_By_Default_Async() - { - using (var application = await AbpApplicationFactory.CreateAsync()) - { - application.Services.AddType(typeof(MyServiceAsync)); - - await application.InitializeAsync(); - - var serviceScopeFactory = application.ServiceProvider.GetRequiredService(); - - using (var scope = serviceScopeFactory.CreateScope()) - { - scope.ServiceProvider.GetRequiredService(); - } - - MyServiceAsync.DisposeCount.ShouldBe(1); - } - } - - [Fact] - public void Should_Use_Default_ServiceScopeFactory_By_Default() - { - using (var application = AbpApplicationFactory.Create()) - { - application.Services.AddType(typeof(MyService)); - - application.Initialize(); - - var serviceScopeFactory = application.ServiceProvider.GetRequiredService(); - - using (var scope = serviceScopeFactory.CreateScope()) - { - scope.ServiceProvider.GetRequiredService(); - } - - MyService.DisposeCount.ShouldBe(1); - } - } - - private class MyServiceAsync : ITransientDependency, IDisposable - { - public static int DisposeCount { get; private set; } - - public void Dispose() - { - ++DisposeCount; - } - } - - private class MyService : ITransientDependency, IDisposable - { - public static int DisposeCount { get; private set; } - - public void Dispose() - { - ++DisposeCount; - } - } -} diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs index 06c293219b..36800a9a33 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureManager.cs @@ -29,7 +29,7 @@ public class FeatureManager : IFeatureManager, ISingletonDependency StringLocalizerFactory = stringLocalizerFactory; Options = options.Value; - //TODO: Instead, use IHybridServiceScopeFactory and create a scope..? + //TODO: Instead, use IServiceScopeFactory and create a scope..? _lazyProviders = new Lazy>( () => Options diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs index ac6c9d9edf..bc711254f1 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpCorsPolicyService.cs @@ -17,13 +17,13 @@ namespace Volo.Abp.IdentityServer; public class AbpCorsPolicyService : ICorsPolicyService { public ILogger Logger { get; set; } - protected IHybridServiceScopeFactory HybridServiceScopeFactory { get; } + protected IServiceScopeFactory HybridServiceScopeFactory { get; } protected IDistributedCache Cache { get; } protected IdentityServerOptions Options { get; } public AbpCorsPolicyService( IDistributedCache cache, - IHybridServiceScopeFactory hybridServiceScopeFactory, + IServiceScopeFactory hybridServiceScopeFactory, IOptions options) { Cache = cache; diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs index 82658ceccd..32d2d1eb73 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpWildcardSubdomainCorsPolicyService.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Threading.Tasks; using IdentityServer4.Configuration; using Microsoft.Extensions.Options; +using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.Text.Formatting; @@ -13,7 +14,7 @@ public class AbpWildcardSubdomainCorsPolicyService : AbpCorsPolicyService { public AbpWildcardSubdomainCorsPolicyService( IDistributedCache cache, - IHybridServiceScopeFactory hybridServiceScopeFactory, + IServiceScopeFactory hybridServiceScopeFactory, IOptions options) : base(cache, hybridServiceScopeFactory, options) { diff --git a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs index 77181a8b8b..cf69fda91a 100644 --- a/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs +++ b/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AspNetIdentity/AbpResourceOwnerPasswordValidator.cs @@ -32,7 +32,7 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator protected IdentitySecurityLogManager IdentitySecurityLogManager { get; } protected ILogger> Logger { get; } protected IStringLocalizer Localizer { get; } - protected IHybridServiceScopeFactory ServiceScopeFactory { get; } + protected IServiceScopeFactory ServiceScopeFactory { get; } protected AbpIdentityOptions AbpIdentityOptions { get; } protected IOptions IdentityOptions { get; } @@ -43,7 +43,7 @@ public class AbpResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator ILogger> logger, IStringLocalizer localizer, IOptions abpIdentityOptions, - IHybridServiceScopeFactory serviceScopeFactory, + IServiceScopeFactory serviceScopeFactory, IOptions identityOptions) { UserManager = userManager; diff --git a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs index 49d415c927..1484ea4b52 100644 --- a/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs +++ b/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Controllers/TokenController.Password.cs @@ -22,7 +22,7 @@ namespace Volo.Abp.OpenIddict.Controllers; public partial class TokenController { - protected IHybridServiceScopeFactory ServiceScopeFactory => LazyServiceProvider.LazyGetRequiredService(); + protected IServiceScopeFactory ServiceScopeFactory => LazyServiceProvider.LazyGetRequiredService(); protected ITenantConfigurationProvider TenantConfigurationProvider=> LazyServiceProvider.LazyGetRequiredService(); protected IOptions AbpIdentityOptions => LazyServiceProvider.LazyGetRequiredService>(); protected IOptions IdentityOptions => LazyServiceProvider.LazyGetRequiredService>(); diff --git a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs index 14629b988e..570c99925b 100644 --- a/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs +++ b/modules/setting-management/src/Volo.Abp.SettingManagement.Domain/Volo/Abp/SettingManagement/SettingManager.cs @@ -27,7 +27,7 @@ public class SettingManager : ISettingManager, ISingletonDependency SettingEncryptionService = settingEncryptionService; Options = options.Value; - //TODO: Instead, use IHybridServiceScopeFactory and create a scope..? + //TODO: Instead, use IServiceScopeFactory and create a scope..? _lazyProviders = new Lazy>( () => Options