Make UOW ignored URLs configurable and move blazor endpoint configuration into the framework.

pull/8113/head
Halil İbrahim Kalkan 5 years ago
parent ffad819d2a
commit 1414d3a187

@ -1,5 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Volo.Abp.AspNetCore.Uow;
using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.Components.Server
@ -12,6 +16,20 @@ namespace Volo.Abp.AspNetCore.Components.Server
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddServerSideBlazor();
Configure<AbpAspNetCoreUnitOfWorkOptions>(options =>
{
options.IgnoredUrls.AddIfNotContains("/_blazor");
});
Configure<AbpEndpointRouterOptions>(options =>
{
options.EndpointConfigureActions.Add(endpointContext =>
{
endpointContext.Endpoints.MapBlazorHub();
endpointContext.Endpoints.MapFallbackToPage("/_Host");
});
});
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Uow
{
public class AbpAspNetCoreUnitOfWorkOptions
{
/// <summary>
/// This is used to disable the <see cref="AbpUnitOfWorkMiddleware"/>,
/// app.UseUnitOfWork(), for the specified URLs.
/// <see cref="AbpUnitOfWorkMiddleware"/> will be disabled for URLs
/// starting with an ignored URL.
/// </summary>
public List<string> IgnoredUrls { get; } = new List<string>();
}
}

@ -1,5 +1,7 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Uow;
@ -8,17 +10,20 @@ namespace Volo.Abp.AspNetCore.Uow
public class AbpUnitOfWorkMiddleware : IMiddleware, ITransientDependency
{
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly AbpAspNetCoreUnitOfWorkOptions _options;
public AbpUnitOfWorkMiddleware(IUnitOfWorkManager unitOfWorkManager)
public AbpUnitOfWorkMiddleware(
IUnitOfWorkManager unitOfWorkManager,
IOptions<AbpAspNetCoreUnitOfWorkOptions> options)
{
_unitOfWorkManager = unitOfWorkManager;
_options = options.Value;
}
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
//TODO: Make this configurable.
if (context.Request.Path.Value != null &&
context.Request.Path.Value.StartsWith("/_blazor"))
_options.IgnoredUrls.Any(x => context.Request.Path.Value.StartsWith(x)))
{
await next(context);
return;

@ -261,12 +261,7 @@ namespace MyCompanyName.MyProjectName.Blazor.Server
app.UseUnitOfWork();
app.UseIdentityServer();
app.UseAuthorization();
app.UseConfiguredEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
app.UseConfiguredEndpoints();
}
}
}

Loading…
Cancel
Save