Browse Source

Add `AbpUowHubFilter `.

pull/11807/head
maliming 4 years ago
parent
commit
d22f02c7fe
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  1. 2
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpAspNetCoreSignalRModule.cs
  2. 42
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/Uow/AbpUowHubFilter.cs
  3. 15
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/Uow/AbpUowHubFilterOptions.cs

2
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpAspNetCoreSignalRModule.cs

@ -10,6 +10,7 @@ using Microsoft.Extensions.Options;
using Volo.Abp.AspNetCore.Auditing;
using Volo.Abp.AspNetCore.SignalR.Auditing;
using Volo.Abp.AspNetCore.SignalR.Authentication;
using Volo.Abp.AspNetCore.SignalR.Uow;
using Volo.Abp.Auditing;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity;
@ -39,6 +40,7 @@ public class AbpAspNetCoreSignalRModule : AbpModule
{
options.AddFilter<AbpHubContextAccessorHubFilter>();
options.AddFilter<AbpAuthenticationHubFilter>();
options.AddFilter<AbpUowHubFilter>();
options.AddFilter<AbpAuditHubFilter>();
});

42
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/Uow/AbpUowHubFilter.cs

@ -0,0 +1,42 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.Uow;
namespace Volo.Abp.AspNetCore.SignalR.Uow;
public class AbpUowHubFilter : IHubFilter
{
public virtual async ValueTask<object> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object>> next)
{
object result = null;
var options = await CreateOptionsAsync(invocationContext);
var unitOfWorkManager = invocationContext.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
using (var uow = unitOfWorkManager.Begin(options))
{
result = await next(invocationContext);
await uow.CompleteAsync();
}
return result;
}
private async Task<AbpUnitOfWorkOptions> CreateOptionsAsync(HubInvocationContext invocationContext)
{
var options = new AbpUnitOfWorkOptions();
var defaultOptions = invocationContext.ServiceProvider.GetRequiredService<IOptions<AbpUnitOfWorkDefaultOptions>>().Value;
var uowHubFilterOptions = invocationContext.ServiceProvider.GetRequiredService<IOptions<AbpUowHubFilterOptions>>().Value;
options.IsTransactional = defaultOptions.CalculateIsTransactional(
autoValue: invocationContext.ServiceProvider.GetRequiredService<IUnitOfWorkTransactionBehaviourProvider>().IsTransactional
?? await uowHubFilterOptions.IsTransactional(invocationContext)
);
return options;
}
}

15
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/Uow/AbpUowHubFilterOptions.cs

@ -0,0 +1,15 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
namespace Volo.Abp.AspNetCore.SignalR.Uow;
public class AbpUowHubFilterOptions
{
public Func<HubInvocationContext, Task<bool>> IsTransactional { get; set; }
public AbpUowHubFilterOptions()
{
IsTransactional = context => Task.FromResult<bool>(true);
}
}
Loading…
Cancel
Save