From 83dda99bdad4d8afe49c98893378b8d14f0fa698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Sat, 4 Jun 2022 23:15:41 +0300 Subject: [PATCH] Introduced IntegrationService --- .../Volo/Abp/Auditing/AbpAuditingOptions.cs | 6 + .../Volo.Abp.Core/Volo/Abp/IRemoteService.cs | 2 +- .../Services/IApplicationService.cs | 5 +- .../Application/AbpDddApplicationModule.cs | 4 +- .../Services/ApplicationService.cs | 133 +----------------- .../Services/ApplicationServiceBase.cs | 133 ++++++++++++++++++ .../Services/IntegrationService.cs | 7 + .../Services/IntegrationServiceAttribute.cs | 9 ++ 8 files changed, 163 insertions(+), 136 deletions(-) create mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationServiceBase.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationService.cs create mode 100644 framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationServiceAttribute.cs diff --git a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs index b3c6aeb051..441cd8ef23 100644 --- a/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs +++ b/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AbpAuditingOptions.cs @@ -37,6 +37,12 @@ public class AbpAuditingOptions /// Default: true. /// public bool AlwaysLogOnException { get; set; } + + /// + /// Disables/enables audit logging for integration services. + /// Default: false. + /// + public bool IsEnabledForIntegrationServices { get; set; } public List>> AlwaysLogSelectors { get; } diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/IRemoteService.cs b/framework/src/Volo.Abp.Core/Volo/Abp/IRemoteService.cs index f17a0619dc..613781629c 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/IRemoteService.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/IRemoteService.cs @@ -1,5 +1,5 @@ namespace Volo.Abp; -public interface IRemoteService //TODO: Can we move this to another package? +public interface IRemoteService { } diff --git a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IApplicationService.cs b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IApplicationService.cs index 34fe187f81..ce59e46832 100644 --- a/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IApplicationService.cs +++ b/framework/src/Volo.Abp.Ddd.Application.Contracts/Volo/Abp/Application/Services/IApplicationService.cs @@ -3,8 +3,7 @@ /// /// This interface must be implemented by all application services to register and identify them by convention. /// -public interface IApplicationService : - IRemoteService +public interface IApplicationService : IRemoteService { -} +} \ No newline at end of file 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 38a7efdb2e..0608171aeb 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 @@ -33,10 +33,10 @@ public class AbpDddApplicationModule : AbpModule { Configure(options => { - //TODO: Should we move related items to their own projects? - options.IgnoredInterfaces.AddIfNotContains(typeof(IRemoteService)); + options.IgnoredInterfaces.AddIfNotContains(typeof(IRemoteService)); options.IgnoredInterfaces.AddIfNotContains(typeof(IApplicationService)); options.IgnoredInterfaces.AddIfNotContains(typeof(IUnitOfWorkEnabled)); + //TODO: Should we add others, like IAuditingEnabled...? }); } } 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 03b2857ddc..8389cf3fa4 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,133 +1,6 @@ -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 : - IApplicationService, - IAvoidDuplicateCrossCuttingConcerns, - IValidationEnabled, - IUnitOfWorkEnabled, - IAuditingEnabled, - IGlobalFeatureCheckingEnabled, - ITransientDependency +public abstract class ApplicationService : ApplicationServiceBase { - public IAbpLazyServiceProvider LazyServiceProvider { get; set; } - - [Obsolete("Use LazyServiceProvider instead.")] - public IServiceProvider ServiceProvider { get; set; } - - public static string[] CommonPostfixes { get; set; } = { "AppService", "ApplicationService", "Service" }; - - public List AppliedCrossCuttingConcerns { get; } = new List(); - - 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; - } -} + +} \ No newline at end of file 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 new file mode 100644 index 0000000000..7ed9ba5d5a --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/ApplicationServiceBase.cs @@ -0,0 +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 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 new file mode 100644 index 0000000000..805c3891af --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationService.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.Application.Services; + +[IntegrationService] +public abstract class IntegrationService : ApplicationServiceBase +{ + +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationServiceAttribute.cs b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationServiceAttribute.cs new file mode 100644 index 0000000000..4ba048a2f2 --- /dev/null +++ b/framework/src/Volo.Abp.Ddd.Application/Volo/Abp/Application/Services/IntegrationServiceAttribute.cs @@ -0,0 +1,9 @@ +using System; + +namespace Volo.Abp.Application.Services; + +[AttributeUsage(AttributeTargets.Class)] +public class IntegrationServiceAttribute : Attribute +{ + +} \ No newline at end of file