Browse Source

Disable the `DynamicProxy` for `ConventionalControllers`.

Because it becomes an MVC controller, it has global filters.
Resolve #18845
pull/18874/head
maliming 2 years ago
parent
commit
bd7aa6df02
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 4
      docs/en/API/Auto-API-Controllers.md
  2. 2
      docs/en/Integration-Services.md
  3. 4
      docs/zh-Hans/API/Auto-API-Controllers.md
  4. 13
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
  5. 15
      framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DynamicProxyIgnoreTypes.cs
  6. 26
      framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs

4
docs/en/API/Auto-API-Controllers.md

@ -12,9 +12,9 @@ Basic configuration is simple. Just configure `AbpAspNetCoreMvcOptions` and use
[DependsOn(BookStoreApplicationModule)]
public class BookStoreWebModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
public override void PreConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpAspNetCoreMvcOptions>(options =>
PreConfigure<AbpAspNetCoreMvcOptions>(options =>
{
options
.ConventionalControllers

2
docs/en/Integration-Services.md

@ -93,7 +93,7 @@ Configure<AbpAuditingOptions>(options =>
You can filter integration services (or non-integration services) while creating [Auto API Controllers](API/Auto-API-Controllers.md), using the `ApplicationServiceTypes` option of the `ConventionalControllerSetting` by configuring the `AbpAspNetCoreMvcOptions` as shown below:
```csharp
Configure<AbpAspNetCoreMvcOptions>(options =>
PreConfigure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(
typeof(MyApplicationModule).Assembly,

4
docs/zh-Hans/API/Auto-API-Controllers.md

@ -12,9 +12,9 @@ ABP可以按照惯例 **自动** 将你的应用程序服务配置为API控制
[DependsOn(BookStoreApplicationModule)]
public class BookStoreWebModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
public override void PreConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpAspNetCoreMvcOptions>(options =>
PreConfigure<AbpAspNetCoreMvcOptions>(options =>
{
options
.ConventionalControllers

13
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs

@ -212,6 +212,17 @@ public class AbpAspNetCoreMvcModule : AbpModule
context.Services.GetSingletonInstance<ApplicationPartManager>(),
context.Services.GetSingletonInstance<IModuleContainer>()
);
var preConfigureActions = context.Services.GetPreConfigureActions<AbpAspNetCoreMvcOptions>();
DynamicProxyIgnoreTypes.Add(preConfigureActions.Configure()
.ConventionalControllers
.ConventionalControllerSettings.SelectMany(x => x.ControllerTypes).ToArray());
Configure<AbpAspNetCoreMvcOptions>(options =>
{
preConfigureActions.Configure(options);
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
@ -247,7 +258,7 @@ public class AbpAspNetCoreMvcModule : AbpModule
.Distinct();
AddToApplicationParts(partManager, controllerAssemblies);
var additionalAssemblies = moduleContainer
.Modules
.SelectMany(m => m.GetAdditionalAssemblies())

15
framework/src/Volo.Abp.Core/Volo/Abp/DynamicProxy/DynamicProxyIgnoreTypes.cs

@ -17,10 +17,23 @@ public static class DynamicProxyIgnoreTypes
private static HashSet<Type> IgnoredTypes { get; } = new HashSet<Type>();
public static void Add<T>()
{
Add(typeof(T));
}
public static void Add(Type type)
{
lock (IgnoredTypes)
{
IgnoredTypes.AddIfNotContains(type);
}
}
public static void Add(params Type[] types)
{
lock (IgnoredTypes)
{
IgnoredTypes.AddIfNotContains(typeof(T));
IgnoredTypes.AddIfNotContains(types);
}
}

26
framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcTestModule.cs

@ -44,6 +44,19 @@ public class AbpAspNetCoreMvcTestModule : AbpModule
typeof(AbpAspNetCoreMvcTestModule).Assembly
);
});
context.Services.PreConfigure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(TestAppModule).Assembly, opts =>
{
opts.UrlActionNameNormalizer = urlActionNameNormalizerContext =>
string.Equals(urlActionNameNormalizerContext.ActionNameInUrl, "phone", StringComparison.OrdinalIgnoreCase)
? "phones"
: urlActionNameNormalizerContext.ActionNameInUrl;
});
options.ExposeIntegrationServices = true;
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
@ -79,19 +92,6 @@ public class AbpAspNetCoreMvcTestModule : AbpModule
});
});
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(TestAppModule).Assembly, opts =>
{
opts.UrlActionNameNormalizer = urlActionNameNormalizerContext =>
string.Equals(urlActionNameNormalizerContext.ActionNameInUrl, "phone", StringComparison.OrdinalIgnoreCase)
? "phones"
: urlActionNameNormalizerContext.ActionNameInUrl;
});
options.ExposeIntegrationServices = true;
});
Configure<AbpVirtualFileSystemOptions>(options =>
{
options.FileSets.AddEmbedded<AbpAspNetCoreMvcTestModule>();

Loading…
Cancel
Save