From 4f42ff1ee0e7c57fc8e9b1bf84f5738d1e701038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Thu, 8 Sep 2022 13:19:06 +0300 Subject: [PATCH] Remove ApplicationServiceBase --- .../Application/AbpDddApplicationModule.cs | 6 +- .../Services/ApplicationService.cs | 133 +++++++++++++++++- .../Services/ApplicationServiceBase.cs | 133 ------------------ .../Services/IntegrationService.cs | 7 - 4 files changed, 135 insertions(+), 144 deletions(-) delete mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationServiceBase.cs delete mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationService.cs diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/AbpDddApplicationModule.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/AbpDddApplicationModule.cs index 0608171aeb..bef608a6ff 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/AbpDddApplicationModule.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/AbpDddApplicationModule.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; using Volo.Abp.Application.Services; +using Volo.Abp.Aspects; +using Volo.Abp.Auditing; using Volo.Abp.Authorization; using Volo.Abp.Domain; using Volo.Abp.Features; @@ -36,7 +38,9 @@ public class AbpDddApplicationModule : AbpModule options.IgnoredInterfaces.AddIfNotContains(typeof(IRemoteService)); options.IgnoredInterfaces.AddIfNotContains(typeof(IApplicationService)); options.IgnoredInterfaces.AddIfNotContains(typeof(IUnitOfWorkEnabled)); - //TODO: Should we add others, like IAuditingEnabled...? + options.IgnoredInterfaces.AddIfNotContains(typeof(IAuditingEnabled)); + options.IgnoredInterfaces.AddIfNotContains(typeof(IValidationEnabled)); + options.IgnoredInterfaces.AddIfNotContains(typeof(IGlobalFeatureCheckingEnabled)); }); } } diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs index 8389cf3fa4..b24e4b2900 100644 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationService.cs @@ -1,6 +1,133 @@ +using JetBrains.Annotations; +using Microsoft.AspNetCore.Authorization; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Localization; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Aspects; +using Volo.Abp.Auditing; +using Volo.Abp.Authorization; +using Volo.Abp.Data; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Features; +using Volo.Abp.GlobalFeatures; +using Volo.Abp.Guids; +using Volo.Abp.Linq; +using Volo.Abp.Localization; +using Volo.Abp.MultiTenancy; +using Volo.Abp.ObjectMapping; +using Volo.Abp.Settings; +using Volo.Abp.Timing; +using Volo.Abp.Uow; +using Volo.Abp.Users; +using Volo.Abp.Validation; + namespace Volo.Abp.Application.Services; -public abstract class ApplicationService : ApplicationServiceBase +public abstract class ApplicationService : + IApplicationService, + IAvoidDuplicateCrossCuttingConcerns, + IValidationEnabled, + IUnitOfWorkEnabled, + IAuditingEnabled, + IGlobalFeatureCheckingEnabled, + ITransientDependency { - -} \ No newline at end of file + public IAbpLazyServiceProvider LazyServiceProvider { get; set; } + + [Obsolete("Use LazyServiceProvider instead.")] + public IServiceProvider ServiceProvider { get; set; } + + public static string[] CommonPostfixes { get; set; } = { "AppService", "ApplicationService", "IntService", "IntegrationService", "Service" }; + + public List AppliedCrossCuttingConcerns { get; } = new(); + + protected IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService(); + + protected IAsyncQueryableExecuter AsyncExecuter => LazyServiceProvider.LazyGetRequiredService(); + + protected Type ObjectMapperContext { get; set; } + protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService(provider => + ObjectMapperContext == null + ? provider.GetRequiredService() + : (IObjectMapper)provider.GetRequiredService(typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext))); + + protected IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetService(SimpleGuidGenerator.Instance); + + protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService(); + + protected ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService(); + + protected IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService(); + + protected ICurrentUser CurrentUser => LazyServiceProvider.LazyGetRequiredService(); + + protected ISettingProvider SettingProvider => LazyServiceProvider.LazyGetRequiredService(); + + protected IClock Clock => LazyServiceProvider.LazyGetRequiredService(); + + protected IAuthorizationService AuthorizationService => LazyServiceProvider.LazyGetRequiredService(); + + protected IFeatureChecker FeatureChecker => LazyServiceProvider.LazyGetRequiredService(); + + protected IStringLocalizerFactory StringLocalizerFactory => LazyServiceProvider.LazyGetRequiredService(); + + protected IStringLocalizer L { + get { + if (_localizer == null) + { + _localizer = CreateLocalizer(); + } + + return _localizer; + } + } + private IStringLocalizer _localizer; + + protected Type LocalizationResource { + get => _localizationResource; + set { + _localizationResource = value; + _localizer = null; + } + } + private Type _localizationResource = typeof(DefaultResource); + + protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; + + protected ILogger Logger => LazyServiceProvider.LazyGetService(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance); + + /// + /// Checks for given . + /// Throws if given policy has not been granted. + /// + /// The policy name. This method does nothing if given is null or empty. + protected virtual async Task CheckPolicyAsync([CanBeNull] string policyName) + { + if (string.IsNullOrEmpty(policyName)) + { + return; + } + + await AuthorizationService.CheckAsync(policyName); + } + + protected virtual IStringLocalizer CreateLocalizer() + { + if (LocalizationResource != null) + { + return StringLocalizerFactory.Create(LocalizationResource); + } + + var localizer = StringLocalizerFactory.CreateDefaultOrNull(); + if (localizer == null) + { + throw new AbpException($"Set {nameof(LocalizationResource)} or define the default localization resource type (by configuring the {nameof(AbpLocalizationOptions)}.{nameof(AbpLocalizationOptions.DefaultResourceType)}) to be able to use the {nameof(L)} object!"); + } + + return localizer; + } +} diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationServiceBase.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationServiceBase.cs deleted file mode 100644 index 7ed9ba5d5a..0000000000 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationServiceBase.cs +++ /dev/null @@ -1,133 +0,0 @@ -using JetBrains.Annotations; -using Microsoft.AspNetCore.Authorization; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Abstractions; -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Volo.Abp.Aspects; -using Volo.Abp.Auditing; -using Volo.Abp.Authorization; -using Volo.Abp.Data; -using Volo.Abp.DependencyInjection; -using Volo.Abp.Features; -using Volo.Abp.GlobalFeatures; -using Volo.Abp.Guids; -using Volo.Abp.Linq; -using Volo.Abp.Localization; -using Volo.Abp.MultiTenancy; -using Volo.Abp.ObjectMapping; -using Volo.Abp.Settings; -using Volo.Abp.Timing; -using Volo.Abp.Uow; -using Volo.Abp.Users; -using Volo.Abp.Validation; - -namespace Volo.Abp.Application.Services; - -public abstract class ApplicationServiceBase : - IApplicationService, - IAvoidDuplicateCrossCuttingConcerns, - IValidationEnabled, - IUnitOfWorkEnabled, - IAuditingEnabled, - IGlobalFeatureCheckingEnabled, - ITransientDependency -{ - public IAbpLazyServiceProvider LazyServiceProvider { get; set; } - - [Obsolete("Use LazyServiceProvider instead.")] - public IServiceProvider ServiceProvider { get; set; } - - public static string[] CommonPostfixes { get; set; } = { "AppService", "ApplicationService", "IntService", "IntegrationService", "Service" }; - - public List AppliedCrossCuttingConcerns { get; } = new(); - - protected IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService(); - - protected IAsyncQueryableExecuter AsyncExecuter => LazyServiceProvider.LazyGetRequiredService(); - - protected Type ObjectMapperContext { get; set; } - protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService(provider => - ObjectMapperContext == null - ? provider.GetRequiredService() - : (IObjectMapper)provider.GetRequiredService(typeof(IObjectMapper<>).MakeGenericType(ObjectMapperContext))); - - protected IGuidGenerator GuidGenerator => LazyServiceProvider.LazyGetService(SimpleGuidGenerator.Instance); - - protected ILoggerFactory LoggerFactory => LazyServiceProvider.LazyGetRequiredService(); - - protected ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService(); - - protected IDataFilter DataFilter => LazyServiceProvider.LazyGetRequiredService(); - - protected ICurrentUser CurrentUser => LazyServiceProvider.LazyGetRequiredService(); - - protected ISettingProvider SettingProvider => LazyServiceProvider.LazyGetRequiredService(); - - protected IClock Clock => LazyServiceProvider.LazyGetRequiredService(); - - protected IAuthorizationService AuthorizationService => LazyServiceProvider.LazyGetRequiredService(); - - protected IFeatureChecker FeatureChecker => LazyServiceProvider.LazyGetRequiredService(); - - protected IStringLocalizerFactory StringLocalizerFactory => LazyServiceProvider.LazyGetRequiredService(); - - protected IStringLocalizer L { - get { - if (_localizer == null) - { - _localizer = CreateLocalizer(); - } - - return _localizer; - } - } - private IStringLocalizer _localizer; - - protected Type LocalizationResource { - get => _localizationResource; - set { - _localizationResource = value; - _localizer = null; - } - } - private Type _localizationResource = typeof(DefaultResource); - - protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; - - protected ILogger Logger => LazyServiceProvider.LazyGetService(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance); - - /// - /// Checks for given . - /// Throws if given policy has not been granted. - /// - /// The policy name. This method does nothing if given is null or empty. - protected virtual async Task CheckPolicyAsync([CanBeNull] string policyName) - { - if (string.IsNullOrEmpty(policyName)) - { - return; - } - - await AuthorizationService.CheckAsync(policyName); - } - - protected virtual IStringLocalizer CreateLocalizer() - { - if (LocalizationResource != null) - { - return StringLocalizerFactory.Create(LocalizationResource); - } - - var localizer = StringLocalizerFactory.CreateDefaultOrNull(); - if (localizer == null) - { - throw new AbpException($"Set {nameof(LocalizationResource)} or define the default localization resource type (by configuring the {nameof(AbpLocalizationOptions)}.{nameof(AbpLocalizationOptions.DefaultResourceType)}) to be able to use the {nameof(L)} object!"); - } - - return localizer; - } -} diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationService.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationService.cs deleted file mode 100644 index 805c3891af..0000000000 --- a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationService.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.Abp.Application.Services; - -[IntegrationService] -public abstract class IntegrationService : ApplicationServiceBase -{ - -} \ No newline at end of file