diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Builder/AbpAspNetCoreMvcApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Builder/AbpAspNetCoreMvcApplicationBuilderExtensions.cs
index 9a19337c5f..daa5183709 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Builder/AbpAspNetCoreMvcApplicationBuilderExtensions.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Microsoft/AspNetCore/Builder/AbpAspNetCoreMvcApplicationBuilderExtensions.cs
@@ -15,18 +15,12 @@ namespace Microsoft.AspNetCore.Builder
/// The .
/// Additional action to configure routes
/// A reference to this instance after the operation has completed.
+ [Obsolete("Use app.UseConfiguredEndpoints(...) extension method instead!")]
public static IApplicationBuilder UseMvcWithDefaultRouteAndArea(
this IApplicationBuilder app,
Action additionalConfigurationAction = null)
{
- return app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
- endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
- endpoints.MapRazorPages();
-
- additionalConfigurationAction?.Invoke(endpoints);
- });
+ return app.UseConfiguredEndpoints(additionalConfigurationAction);
}
}
}
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
index 00ba8423b3..ee81e0a22e 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreMvcModule.cs
@@ -13,10 +13,12 @@ using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure;
+using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Localization;
using Volo.Abp.ApiVersioning;
@@ -165,6 +167,16 @@ namespace Volo.Abp.AspNetCore.Mvc
{
mvcOptions.AddAbp(context.Services);
});
+
+ Configure(options =>
+ {
+ options.EndpointConfigureActions.Add(context =>
+ {
+ context.Endpoints.MapControllerRoute("defaultWithArea", "{area}/{controller=Home}/{action=Index}/{id?}");
+ context.Endpoints.MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}");
+ context.Endpoints.MapRazorPages();
+ });
+ });
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs
index 526470b3ad..2ef536db4d 100644
--- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs
+++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/DependencyInjection/AbpAspNetCoreMvcConventionalDependencyRegistrar.cs
@@ -29,8 +29,13 @@ namespace Volo.Abp.AspNetCore.Mvc.DependencyInjection
foreach (var serviceType in serviceTypes)
{
- var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime);
- services.Add(serviceDescriptor);
+ services.Add(
+ ServiceDescriptor.Describe(
+ serviceType,
+ type,
+ lifeTime
+ )
+ );
}
}
diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs
new file mode 100644
index 0000000000..1ce443c37f
--- /dev/null
+++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Builder/AbpAspNetCoreApplicationBuilderExtensions.cs
@@ -0,0 +1,47 @@
+using System;
+using System.Linq;
+using Microsoft.AspNetCore.Routing;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+
+namespace Microsoft.AspNetCore.Builder
+{
+ public static class AbpAspNetCoreApplicationBuilderExtensions
+ {
+ ///
+ /// Maps endpoints configured with the .
+ /// It internally uses the standard app.UseEndpoints(...) method.
+ ///
+ /// The application builder
+ /// Additional (and optional) endpoint configuration
+ ///
+ public static IApplicationBuilder UseConfiguredEndpoints(
+ this IApplicationBuilder app,
+ Action additionalConfigurationAction = null)
+ {
+ var options = app.ApplicationServices
+ .GetRequiredService>()
+ .Value;
+
+ if (!options.EndpointConfigureActions.Any())
+ {
+ return app;
+ }
+
+ return app.UseEndpoints(endpoints =>
+ {
+ using (var scope = app.ApplicationServices.CreateScope())
+ {
+ var context = new EndpointRouteBuilderContext(endpoints, scope.ServiceProvider);
+
+ foreach (var configureAction in options.EndpointConfigureActions)
+ {
+ configureAction(context);
+ }
+
+ additionalConfigurationAction?.Invoke(endpoints);
+ }
+ });
+ }
+ }
+}
diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Routing/AbpEndpointRouterOptions.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Routing/AbpEndpointRouterOptions.cs
new file mode 100644
index 0000000000..85c81a7949
--- /dev/null
+++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Routing/AbpEndpointRouterOptions.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+
+namespace Microsoft.AspNetCore.Routing
+{
+ public class AbpEndpointRouterOptions
+ {
+ public List> EndpointConfigureActions { get; }
+
+ public AbpEndpointRouterOptions()
+ {
+ EndpointConfigureActions = new List>();
+ }
+ }
+}
diff --git a/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Routing/EndpointRouteBuilderContext.cs b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Routing/EndpointRouteBuilderContext.cs
new file mode 100644
index 0000000000..80f25d2d38
--- /dev/null
+++ b/framework/src/Volo.Abp.AspNetCore/Microsoft/AspNetCore/Routing/EndpointRouteBuilderContext.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace Microsoft.AspNetCore.Routing
+{
+ public class EndpointRouteBuilderContext
+ {
+ public IEndpointRouteBuilder Endpoints { get; }
+ public IServiceProvider ScopeServiceProvider { get; }
+
+ public EndpointRouteBuilderContext(
+ IEndpointRouteBuilder endpoints,
+ IServiceProvider scopeServiceProvider)
+ {
+ Endpoints = endpoints;
+ ScopeServiceProvider = scopeServiceProvider;
+ }
+ }
+}
\ No newline at end of file