我在我的控制器中设置 DI,如下所示,并绑定到注册 IHubContext,如它所见
控制器:
public class DemoController : Controller
{
private IHubContext<DemoHub> context;
public DemoController(IHubContext<DemoHub> context)
{
this.context = context;
}
}
全球.asax:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
BundleConfig.RegisterBundles(BundleTable.Bundles);
var container = new Container();
container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
container.Register<IHubContext, IHubContext>(Lifestyle.Scoped);
// or
container.Register<IHubContext>(Lifestyle.Scoped);
// code omitted
}
但是当我调试我的应用程序时,遇到“ System.ArgumentException:'给定类型 IHubContext 不是具体类型。请使用其他重载之一来注册此类型。参数名称:TImplementation' ”错误。那么,如何正确注册 IHubContext 呢?