-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using Reflection to create a kestrel client for unit testing
- Loading branch information
Showing
2 changed files
with
89 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Connections; | ||
using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace SuperSocket.Tests; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
private const string SocketConnectionFactoryTypeName = | ||
"Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.SocketConnectionFactory"; | ||
|
||
private static Type FindSocketConnectionFactory() | ||
{ | ||
var assembly = typeof(SocketTransportOptions).Assembly; | ||
var connectionFactoryType = assembly.GetType(SocketConnectionFactoryTypeName); | ||
return connectionFactoryType ?? throw new NotSupportedException(SocketConnectionFactoryTypeName); | ||
} | ||
|
||
public static IServiceCollection AddSocketConnectionFactory(this IServiceCollection services) | ||
{ | ||
var factoryType = FindSocketConnectionFactory(); | ||
return services.AddSingleton(typeof(IConnectionFactory), factoryType); | ||
} | ||
} |