aspnetcore/src/Microsoft.AspNetCore.SignalR/InvocationAdapterRegistry.cs

29 lines
857 B
C#

using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.SignalR
{
public class InvocationAdapterRegistry
{
private readonly IServiceProvider _serviceProvider;
private readonly SignalROptions _options;
public InvocationAdapterRegistry(IOptions<SignalROptions> options, IServiceProvider serviceProvider)
{
_options = options.Value;
_serviceProvider = serviceProvider;
}
public IInvocationAdapter GetInvocationAdapter(string format)
{
Type type;
if (_options._invocationMappings.TryGetValue(format, out type))
{
return _serviceProvider.GetRequiredService(type) as IInvocationAdapter;
}
return null;
}
}
}