Note that there are some explanatory texts on larger screens.

plurals
  1. POSignalR cannot call client function when using StructureMap dependency resolver
    primarykey
    data
    text
    <p>When I include a structuremap dependency resolver in my global.asax for signalR any calls to client functions no longer arrive at the browser although I can see them if in the logging pipeline.</p> <p>Here's an extract of my global.asax:</p> <pre><code>var container = ObjectFactory.Container; // Now configure SignalR, MVC, ASP.Net and SharpRepository GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule()); GlobalHost.HubPipeline.AddModule(new LoggingPipelineModule()); // TODO: Work out why this breaks the connection between the server and the client. GlobalHost.DependencyResolver = ObjectFactory.GetInstance&lt;IDependencyResolver&gt;(); RouteTable.Routes.MapHubs(); DependencyResolver.SetResolver( new StructureMapDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new StructureMapDependencyResolver(container); RepositoryDependencyResolver.SetDependencyResolver( new SharpRepository.Ioc.StructureMap.StructureMapDependencyResolver(container)); </code></pre> <p>Here the implementation of the structuremap resolver:</p> <pre><code>public class StructureMapSignalRDependencyResolver : DefaultDependencyResolver { private readonly IContainer _container; public StructureMapSignalRDependencyResolver( IContainer container) { if (container == null) { throw new ArgumentNullException("container"); } _container = container; } public override object GetService(Type serviceType) { object result = null; try { result = !serviceType.IsAbstract &amp;&amp; !serviceType.IsInterface &amp;&amp; serviceType.IsClass ? _container.GetInstance(serviceType) : (_container.TryGetInstance(serviceType) ?? base.GetService(serviceType)); } catch (Exception ex) { Tracing.Error( "[StructureMapSignalRDependencyResolver]", Tracing.SerializeException(ex)); } if (result == null) { Tracing.Information( "[StructureMapSignalRDependencyResolver]", "Could retrieve object of type {0}",serviceType.ToString()); } return result; } public override IEnumerable&lt;object&gt; GetServices( Type serviceType) { IEnumerable&lt;object&gt; result = null; try { result = _container.GetAllInstances(serviceType) .Cast&lt;object&gt;().Concat( base.GetServices(serviceType)); } catch (Exception ex) { Tracing.Error( "[StructureMapSignalRDependencyResolver]", Tracing.SerializeException(ex)); } if (result == null) { Tracing.Information( "[StructureMapSignalRDependencyResolver]", "Could retrieve object of type {0}", serviceType.ToString()); } return result; } public override void Register(Type serviceType, Func&lt;object&gt; activator) { Tracing.Information( "[StructureMapSignalRDependencyResolver]", "Registering object of type {0}", serviceType.ToString()); base.Register(serviceType, activator); } public override void Register(Type serviceType, IEnumerable&lt;Func&lt;object&gt;&gt; activators) { Tracing.Information( "[StructureMapSignalRDependencyResolver]", "Registering object of type {0}", serviceType.ToString()); base.Register(serviceType, activators); } } </code></pre> <p>Here is the implementation of StructureMap Registry (there are many more which include the application assemblies).</p> <pre><code>[RegistryOrder(Order = 6)] public class SignalRRegistry : Registry { public SignalRRegistry() { For&lt;IDependencyResolver&gt;().Singleton() .Use&lt;StructureMapSignalRDependencyResolver&gt;(); For&lt;IHubConnectionContext&gt;().Singleton() .Use(GlobalHost.ConnectionManager .GetHubContext&lt;BOSSHub&gt;().Clients); } //public void Configure() //{ // GlobalHost.DependencyResolver = // ObjectFactory.GetInstance&lt;IDependencyResolver&gt;(); // RouteTable.Routes.MapHubs(); //} } </code></pre> <p>I've rolled back the Hub class so that it no longer has an dependencies; the output from WhatDoIHave seems to have some entries for Microsoft.AspNet.SignalR but without any concrete relationships.</p> <p>I wondering if I missed a step in my registry ? I get no exceptions anywhere; it just stops working, if I comment out the GlobalHost.DependencyResolver line from global.asax all is well.</p> <p>I hope someone could share with me a DI implementation for signalR that is working for them.</p> <p>Many Thanks</p> <p>UPDATE: Thanks for sorting out the bad formatting for me - appreciate that.</p> <p>UPDATE: I've put together a small test project which shows the issue. I was surprised if I'm honest I was able to reproduce it as the application that I'm working on it pretty big and complex with lot's of StructureMap stuff going on. I've uploaded into GitHub : <a href="https://github.com/johnk27stars/SignalRTest.git" rel="nofollow">https://github.com/johnk27stars/SignalRTest.git</a> - Thanks to anyone who could spare a minute to take a look.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload