本文介绍了SignalR 结构图依赖解析器(为 Microsoft.AspNet.SignalR.Messaging.IMessageBus 指定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何解决这个错误?

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 指定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 02:09
查看更多