问题描述
我该如何解决这个错误?
how can i resolve this error ?
版本
Microsoft.AspNet.SignalR.Core 2.2.0,结构图 3.1.4.143
Microsoft.AspNet.SignalR.Core 2.2.0, structuremap 3.1.4.143
global.asax signalR 依赖解析
global.asax signalR dependency resolve
// SIGNALR DEPENDENCY RESOLVER
GlobalHost.DependencyResolver = new StructureMapSignalRDependencyResolver(Container ?? ObjectFactory.Container);
StructureMapSignalRDependencyResolver
StructureMapSignalRDependencyResolver
public class StructureMapSignalRDependencyResolver : DefaultDependencyResolver
{
private readonly IContainer _container;
public StructureMapSignalRDependencyResolver(IContainer container)
{
_container = container;
}
public override object GetService(Type serviceType)
{
object service = null;
//Below is a key difference between this StructureMap example, GetInstance is used for concrete classes.
if (!serviceType.IsAbstract && !serviceType.IsInterface && serviceType.IsClass)
{
//If the type is a concrete type we get here...
service = _container.GetInstance(serviceType);
}
else
{
// Non concrete resolution which uses the base dependency resolver if needed.
service = _container.TryGetInstance(serviceType) ?? base.GetService(serviceType);
}
return service;
}
public override IEnumerable<object> GetServices(Type serviceType)
{
var objects = _container.GetAllInstances(serviceType).Cast<object>();
return objects.Concat(base.GetServices(serviceType));
}
}
错误
未注册默认实例,无法自动确定类型Microsoft.AspNet.SignalR.Messaging.IMessageBus"
No default Instance is registered and cannot be automatically determined for type 'Microsoft.AspNet.SignalR.Messaging.IMessageBus'
没有为 Microsoft.AspNet.SignalR.Messaging.IMessageBus 指定配置
There is no configuration specified for Microsoft.AspNet.SignalR.Messaging.IMessageBus
1.) 新的 AckSubscriber(IMessageBus 的默认值,IAckHandler 的默认值)2.) Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber3.) Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber 的实例4.) Container.GetInstance(Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber)
1.) new AckSubscriber(Default of IMessageBus, Default of IAckHandler)2.) Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber3.) Instance of Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber4.) Container.GetInstance(Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber)
推荐答案
先尝试从基类解决.
public override object GetService(Type serviceType)
{
if (serviceType == null)
return null;
var service = base.GetService(serviceType);
if (service != null) return service;
return (!serviceType.IsAbstract && !serviceType.IsInterface && serviceType.IsClass)
? container.GetInstance(serviceType)
: container.TryGetInstance(serviceType);
}
这篇关于SignalR 结构图依赖解析器(为 Microsoft.AspNet.SignalR.Messaging.IMessageBus 指定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!