Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the DisableAbpFeatures. #18638

Merged
merged 4 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Settings;

namespace Volo.Abp.AspNetCore.MultiTenancy;

public class MultiTenancyMiddleware : IMiddleware, ITransientDependency
public class MultiTenancyMiddleware : AbpMiddlewareBase, ITransientDependency
{
public ILogger<MultiTenancyMiddleware> Logger { get; set; }

Expand All @@ -38,7 +39,7 @@ public class MultiTenancyMiddleware : IMiddleware, ITransientDependency
_options = options.Value;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
TenantConfiguration? tenant = null;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Net;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand All @@ -25,6 +26,7 @@
using Volo.Abp.Application;
using Volo.Abp.AspNetCore.Mvc.AntiForgery;
using Volo.Abp.AspNetCore.Mvc.ApiExploring;
using Volo.Abp.AspNetCore.Mvc.ApplicationModels;
using Volo.Abp.AspNetCore.Mvc.Conventions;
using Volo.Abp.AspNetCore.Mvc.DataAnnotations;
using Volo.Abp.AspNetCore.Mvc.DependencyInjection;
Expand Down Expand Up @@ -176,6 +178,7 @@ public override void ConfigureServices(ServiceConfigurationContext context)
context.Services.Replace(ServiceDescriptor.Singleton<IValidationAttributeAdapterProvider, AbpValidationAttributeAdapterProvider>());
context.Services.AddSingleton<ValidationAttributeAdapterProvider>();

context.Services.TryAddEnumerable(ServiceDescriptor.Transient<IActionDescriptorProvider, AbpMvcActionDescriptorProvider>());
context.Services.AddOptions<MvcOptions>()
.Configure<IServiceProvider>((mvcOptions, serviceProvider) =>
{
Expand Down Expand Up @@ -247,7 +250,7 @@ private static void AddApplicationParts(ApplicationInitializationContext context
.Distinct();

AddToApplicationParts(partManager, controllerAssemblies);

var additionalAssemblies = moduleContainer
.Modules
.SelectMany(m => m.GetAdditionalAssemblies())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Controllers;
using Volo.Abp.AspNetCore.Filters;

namespace Volo.Abp.AspNetCore.Mvc.ApplicationModels;

public class AbpMvcActionDescriptorProvider : IActionDescriptorProvider
{
public virtual int Order => -1000 + 10;

public virtual void OnProvidersExecuting(ActionDescriptorProviderContext context)
{
}

public virtual void OnProvidersExecuted(ActionDescriptorProviderContext context)
{
foreach (var action in context.Results.Where(x => x is ControllerActionDescriptor).Cast<ControllerActionDescriptor>())
{
var disableAbpFeaturesAttribute = action.ControllerTypeInfo.GetCustomAttribute<DisableAbpFeaturesAttribute>(true);
if (disableAbpFeaturesAttribute != null && disableAbpFeaturesAttribute.DisableMvcFilters)
{
action.FilterDescriptors.RemoveAll(x => x.Filter is ServiceFilterAttribute serviceFilterAttribute &&
typeof(IAbpFilter).IsAssignableFrom(serviceFilterAttribute.ServiceType));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;

namespace Volo.Abp.AspNetCore.Mvc.Auditing;

public class AbpAuditActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpAuditActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;

namespace Volo.Abp.AspNetCore.Mvc.Auditing;

public class AbpAuditPageFilter : IAsyncPageFilter, ITransientDependency
public class AbpAuditPageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ExceptionHandling;
Expand All @@ -18,7 +19,7 @@

namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling;

public class AbpExceptionFilter : IAsyncExceptionFilter, ITransientDependency
public class AbpExceptionFilter : IAsyncExceptionFilter, IAbpFilter, ITransientDependency
{
public virtual async Task OnExceptionAsync(ExceptionContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.ExceptionHandling;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ExceptionHandling;
Expand All @@ -18,7 +19,7 @@

namespace Volo.Abp.AspNetCore.Mvc.ExceptionHandling;

public class AbpExceptionPageFilter : IAsyncPageFilter, ITransientDependency
public class AbpExceptionPageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;

namespace Volo.Abp.AspNetCore.Mvc.Features;

public class AbpFeatureActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpFeatureActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Features;

namespace Volo.Abp.AspNetCore.Mvc.Features;

public class AbpFeaturePageFilter : IAsyncPageFilter, ITransientDependency
public class AbpFeaturePageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.GlobalFeatures;

namespace Volo.Abp.AspNetCore.Mvc.GlobalFeatures;

public class GlobalFeatureActionFilter : IAsyncActionFilter, ITransientDependency
public class GlobalFeatureActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Aspects;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.GlobalFeatures;

namespace Volo.Abp.AspNetCore.Mvc.GlobalFeatures;

public class GlobalFeaturePageFilter : IAsyncPageFilter, ITransientDependency
public class GlobalFeaturePageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;

namespace Volo.Abp.AspNetCore.Mvc.Response;

public class AbpNoContentActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpNoContentActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;

namespace Volo.Abp.AspNetCore.Mvc.Uow;

public class AbpUowActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpUowActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.AspNetCore.Uow;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;

namespace Volo.Abp.AspNetCore.Mvc.Uow;

public class AbpUowPageFilter : IAsyncPageFilter, ITransientDependency
public class AbpUowPageFilter : IAsyncPageFilter, IAbpFilter, ITransientDependency
{
public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Filters;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Reflection;
using Volo.Abp.Validation;

namespace Volo.Abp.AspNetCore.Mvc.Validation;

public class AbpValidationActionFilter : IAsyncActionFilter, ITransientDependency
public class AbpValidationActionFilter : IAsyncActionFilter, IAbpFilter, ITransientDependency
{
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Serilog.Context;
using Serilog.Core;
using Serilog.Core.Enrichers;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.Clients;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
Expand All @@ -13,7 +14,7 @@

namespace Volo.Abp.AspNetCore.Serilog;

public class AbpSerilogMiddleware : IMiddleware, ITransientDependency
public class AbpSerilogMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly ICurrentClient _currentClient;
private readonly ICurrentTenant _currentTenant;
Expand All @@ -35,7 +36,7 @@ public class AbpSerilogMiddleware : IMiddleware, ITransientDependency
_options = options.Value;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var enrichers = new List<ILogEventEnricher>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.DependencyInjection;

namespace Microsoft.AspNetCore.RequestLocalization;

public class AbpRequestLocalizationMiddleware : IMiddleware, ITransientDependency
public class AbpRequestLocalizationMiddleware : AbpMiddlewareBase, ITransientDependency
{
public const string HttpContextItemName = "__AbpSetCultureCookie";

Expand All @@ -23,7 +24,7 @@ public class AbpRequestLocalizationMiddleware : IMiddleware, ITransientDependenc
_loggerFactory = loggerFactory;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
var middleware = new RequestLocalizationMiddleware(
next,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
using Volo.Abp.Users;

namespace Volo.Abp.AspNetCore.Auditing;

public class AbpAuditingMiddleware : IMiddleware, ITransientDependency
public class AbpAuditingMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly IAuditingManager _auditingManager;
protected AbpAuditingOptions AuditingOptions { get; }
Expand All @@ -34,9 +35,9 @@ public class AbpAuditingMiddleware : IMiddleware, ITransientDependency
AspNetCoreAuditingOptions = aspNetCoreAuditingOptions.Value;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
if (!AuditingOptions.IsEnabled || IsIgnoredUrl(context))
if (await ShouldSkipAsync(context, next) || !AuditingOptions.IsEnabled || IsIgnoredUrl(context))
{
await next(context);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Volo.Abp.AspNetCore.Middleware;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Authorization;
using Volo.Abp.DependencyInjection;
Expand All @@ -14,7 +15,7 @@

namespace Volo.Abp.AspNetCore.ExceptionHandling;

public class AbpExceptionHandlingMiddleware : IMiddleware, ITransientDependency
public class AbpExceptionHandlingMiddleware : AbpMiddlewareBase, ITransientDependency
{
private readonly ILogger<AbpExceptionHandlingMiddleware> _logger;

Expand All @@ -27,7 +28,7 @@ public AbpExceptionHandlingMiddleware(ILogger<AbpExceptionHandlingMiddleware> lo
_clearCacheHeadersDelegate = ClearCacheHeaders;
}

public async Task InvokeAsync(HttpContext context, RequestDelegate next)
public async override Task InvokeAsync(HttpContext context, RequestDelegate next)
{
try
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Volo.Abp.AspNetCore.Filters;

public interface IAbpFilter
{

}