c# - 在新的 Asp.net Core SignalR 中替换 Globalhost.Dependency 解析器
问题描述
我正在将 .NET Framework 4.8 中的当前代码迁移到新的 .NET Core 5.0。以下是我原来的 Startup.cs。
public class Startup
{
public void Configuration(IAppBuilder app)
{
var container = new UnityContainer();
var unityConfiguration = new UnityConfiguration();
unityConfiguration.RegisterTypes(container);
GlobalHost.DependencyResolver = new UnityDependencyResolver(container);
GlobalHost.HubPipeline.AddModule(new SessionIdCheckModule());
app.UseCors(new CorsOptions
{
PolicyProvider = new WildcardCorsPolicyProvider()
});
var listener = (HttpListener)app.Properties[typeof(HttpListener).FullName];
listener.AuthenticationSchemes = AuthenticationSchemes.Ntlm | AuthenticationSchemes.Negotiate;
//Throttling of http.sys to prevent too many requests being accepted at once.
var maxAccepts = 25;
var maxRequests = 25;
var queueLimit = 25;
var owinListener = (OwinHttpListener)app.Properties[typeof(OwinHttpListener).FullName];
owinListener.SetRequestProcessingLimits(maxAccepts, maxRequests);
owinListener.SetRequestQueueLimit(queueLimit);
TurnOffWebSocket(GlobalHost.DependencyResolver);
app.MapSignalR();
}
//Have to use Ajax long polling as the transport, to get around mixed content blocking in browsers.
public void TurnOffWebSocket(IDependencyResolver resolver)
{
var transportManager = resolver.Resolve<ITransportManager>() as TransportManager;
transportManager.Remove("webSockets");
transportManager.Remove("serverSentEvents");
transportManager.Remove("foreverFrame");
}
}}
任何人都可以建议关注。
- Globalhost.Dependency 解析器的替代品是什么?
- 我想继续将 Unity 用于 DI,而不是在 asp.net 核心的构建 DI 中。我怎样才能做到这一点?
- 什么可以用来实现 HubPipelineModule 的行为?
解决方案
DI 是 ASP.NET Core 中的一流功能,不再是 Globalhost,服务可以在其构造函数中接受来自 DI 的类型。有很多关于 DI 如何工作的例子。
要继续使用 UnityContainer,您需要替换部分 DI,有一篇文章可以帮助解决此问题https://docs.microsoft.com/aspnet/core/migration/proper-to-2x/mvc2?view=aspnetcore- 5.0#native-dependency-injection
HubPipelineModule 被 Hub 过滤器取代https://docs.microsoft.com/aspnet/core/signalr/hub-filters?view=aspnetcore-5.0。
推荐阅读
- html - CSS X 溢出留下空白
- windows - 为什么 Spy++ 看不到发送到 UWP 应用的消息?
- gradle - 使用 Java 9/10 和 Gradle 的 Kotlin DSL 构建 Gradle Kotlin 项目
- async-await - 如何使用 vue + axios 在获取请求中使用 async / await?
- javascript - Ext JS 6.5 菜单自动隐藏
- python - Matplotlib 画布作为 numpy 数组伪影
- python - 将字符串传递给数据框 iloc
- node.js - 如何在设置 laravel-mix 时修复此错误?
- mysql - mysql查询以显示高于平均值的结果,该平均值使用两个表的总和
- c++ - 字符串只包含有效字符?