SignalR, MEF and Dependency Injection working together-Collection of common programming errors
I’m trying to get SignalR, MEF, and MVC working together.
Here is my resolver class:
public class SignalRDependencyResolver : DefaultDependencyResolver
{
private readonly CompositionContainer _container;
public SignalRDependencyResolver(CompositionContainer container)
{
_container = container;
}
public override object GetService(Type serviceType)
{
if (serviceType == null)
{
throw new ArgumentNullException("serviceType");
}
var name = AttributedModelServices.GetContractName(serviceType);
var export = _container.GetExportedValueOrDefault(name);
return export;
}
public override IEnumerable GetServices(Type serviceType)
{
if (serviceType == null)
{
throw new ArgumentNullException("serviceType");
}
var exports = _container.GetExportedValues(AttributedModelServices.GetContractName(serviceType));
return exports;
}
}
And here is my Owin startup:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var resolver = new SignalRDependencyResolver(MefConfigWeb.Container);
var config = new HubConfiguration
{
Resolver = resolver,
};
app.MapSignalR(config);
}
}
I can break on Startup class and see that the container does include my exports. However, Visual Studio prompts with an exception:
Unhandled exception at line 244, column 13 in
http://localhost:3928/Scripts/jquery.signalR-2.0.0.js
0x800a139e – JavaScript runtime error: SignalR: Error loading hubs. Ensure your hubs reference is correct, e.g. .
The app works fine if I don’t set my custom dependency resolver and New up my dependency inside the Hub class.
I am following along from this tutorial: http://www.asp.net/signalr/overview/signalr-20/extensibility/dependency-injection
Any ideas why this is not working?