how can i resolve this error ?
versions
Microsoft.AspNet.SignalR.Core 2.2.0, structuremap 3.1.4.143
global.asax signalR dependency resolve
// SIGNALR DEPENDENCY RESOLVER
GlobalHost.DependencyResolver = new StructureMapSignalRDependencyResolver(Container ?? ObjectFactory.Container);
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));
}
}
erorr
No default Instance is registered and cannot be automatically determined for type 'Microsoft.AspNet.SignalR.Messaging.IMessageBus'
There is no configuration specified for Microsoft.AspNet.SignalR.Messaging.IMessageBus
1.) new AckSubscriber(Default of IMessageBus, Default of IAckHandler) 2.) Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber 3.) Instance of Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber 4.) Container.GetInstance(Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber)
I found temporary, but error continues.. how can i registry this {Name = "AckSubscriber" FullName = "Microsoft.AspNet.SignalR.Infrastructure.AckSubscriber"}
temporary solution is try catch, in catch return null
Try to resolve from the base class first.
I just had a similar problem using a Ninject based resolver. The solution in that case was to ensure that Ninject had a binding for IDependencyResolver, similar to this.
AckSubscriber
has 2 constructors.It would appear that for some reason, rather than trying to create this class via a dependency resolver, it is trying to create this class via the underlying IOC container. Because the bindings for all of this classes are in the
DefaultDependencyResolver
, the container has no idea what they are and so errors. By specifying a binding forIDependencyResolver
it is able to use the first constructor and work as intended.@ajm answer above bypassed the error for me, however I found that none of my client-side methods were being invoked.
It turned out that
SignalR.Infrastructure.PrincipalUserIdProvider
was being resolved instead of my customIUserIdProvider
so I had to modify his answer slightly by adding a container check first.The secondary container checks are still necessary if you are not using StructureMap 3 as
TryGetInstance()
returnsnull
for concrete types.