Browse Source

Added HubConfigList and DisableAutoHubMapAttribute for the signalr integration.

pull/3935/head
Halil İbrahim Kalkan 6 years ago
parent
commit
2619eada34
  1. 21
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpAspNetCoreSignalRModule.cs
  2. 8
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpSignalROptions.cs
  3. 9
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/DisableAutoHubMapAttribute.cs
  4. 8
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/HubConfig.cs
  5. 24
      framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/HubConfigList.cs

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

@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity;
namespace Volo.Abp.AspNetCore.SignalR
@ -30,7 +31,7 @@ namespace Volo.Abp.AspNetCore.SignalR
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddSignalR();
Configure<AbpEndpointRouterOptions>(options =>
{
options.EndpointConfigureActions.Add(endpointContext =>
@ -65,7 +66,7 @@ namespace Volo.Abp.AspNetCore.SignalR
services.OnRegistred(context =>
{
if (typeof(Hub).IsAssignableFrom(context.ImplementationType))
if (IsHubClass(context) && !IsDisabledForAutoMap(context))
{
hubTypes.Add(context.ImplementationType);
}
@ -80,7 +81,17 @@ namespace Volo.Abp.AspNetCore.SignalR
});
}
private void MapHubType(
private static bool IsHubClass(IOnServiceRegistredContext context)
{
return typeof(Hub).IsAssignableFrom(context.ImplementationType);
}
private static bool IsDisabledForAutoMap(IOnServiceRegistredContext context)
{
return context.ImplementationType.IsDefined(typeof(DisableAutoHubMapAttribute), true);
}
private void MapHubType(
Type hubType,
IEndpointRouteBuilder endpoints,
string pattern,
@ -101,8 +112,8 @@ namespace Volo.Abp.AspNetCore.SignalR
// ReSharper disable once UnusedMember.Local (used via reflection)
private static void MapHub<THub>(
IEndpointRouteBuilder endpoints,
string pattern,
IEndpointRouteBuilder endpoints,
string pattern,
Action<HttpConnectionDispatcherOptions> configureOptions)
where THub : Hub
{

8
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/AbpSignalROptions.cs

@ -1,14 +1,12 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.SignalR
namespace Volo.Abp.AspNetCore.SignalR
{
public class AbpSignalROptions
{
public List<HubConfig> Hubs { get; }
public HubConfigList Hubs { get; }
public AbpSignalROptions()
{
Hubs = new List<HubConfig>();
Hubs = new HubConfigList();
}
}
}

9
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/DisableAutoHubMapAttribute.cs

@ -0,0 +1,9 @@
using System;
namespace Volo.Abp.AspNetCore.SignalR
{
public class DisableAutoHubMapAttribute : Attribute
{
}
}

8
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/HubConfig.cs

@ -19,11 +19,17 @@ namespace Volo.Abp.AspNetCore.SignalR
public HubConfig(
[NotNull] Type hubType,
[NotNull] string routePattern)
[NotNull] string routePattern,
[CanBeNull] Action<HttpConnectionDispatcherOptions> configureAction = null)
{
HubType = Check.NotNull(hubType, nameof(hubType));
RoutePattern = Check.NotNullOrWhiteSpace(routePattern, nameof(routePattern));
ConfigureActions = new List<Action<HttpConnectionDispatcherOptions>>();
if (configureAction != null)
{
ConfigureActions.Add(configureAction);
}
}
public static HubConfig Create<THub>()

24
framework/src/Volo.Abp.AspNetCore.SignalR/Volo/Abp/AspNetCore/SignalR/HubConfigList.cs

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Volo.Abp.AspNetCore.SignalR
{
public class HubConfigList : List<HubConfig>
{
public void AddOrUpdate<THub>(Action<HubConfig> configAction = null)
{
AddOrUpdate(typeof(THub));
}
public void AddOrUpdate(Type hubType, Action<HubConfig> configAction = null)
{
var hubConfig = this.GetOrAdd(
c => c.HubType == hubType,
() => HubConfig.Create(hubType)
);
configAction?.Invoke(hubConfig);
}
}
}
Loading…
Cancel
Save