I was able to work with SignalR 1.13 with my own DI like this:
//Funq container
GlobalHost.DependencyResolver = new FunqDependencyResolver(container);
RouteTable.Routes.MapHubs();
Now with the new version 2.0 I am stuck.
using Microsoft.Owin;
using Owin;
//SignalR 2.0 no longer uses RouteTable.Routes.MapHubs();
[assembly: OwinStartup(typeof(SignalRChat.Startup))]
namespace SignalRChat {
public class Startup {
public void Configuration(IAppBuilder app) { app.MapSignalR(); }
}
}
(New SignalR 2.0 setup in VS2013 screenshot)
Firstly, it's a screen from VS2013 from here. my VS2012 Pro doesn't have the Create New ...-> OWIN Startup class.I have hand written one. But now how do I call up the new startup class to replace the old MapHub()
function?
Secondly, I was using the DI that runs the rest of the web project. How do I register signalR to my DI now?
EDIT --------------------------------------------
A bit more to the question. I create my DI container in Global.asax.cs->Application_Start(), but SignalR Startup.cs->Configuration() is automatically created and called. How do I pass my DI container to SignalR Startup?
Global.asax.cs (this runs automatically when app starts)
protected void Application_Start(object sender, EventArgs e)
{
var appHost = new AppHost(); //DI init
appHost.Init();
var container = appHost.Container; //DI container here
var resolver = new FunqDependencyResolver(container);
}
SignalRStarter.cs (this also runs automatically when app starts)
[assembly: OwinStartup(typeof(WebApp.SignalRStarter))]
namespace WebApp {
public class SignalRStarter {
public FunqDependencyResolver FunqDependencyResolver { get; set; }
public bool EnableDetailedErrors { get; set; }
public void Configuration(IAppBuilder app) {
app.MapSignalR(new HubConfiguration() {
EnableDetailedErrors = EnableDetailedErrors,
Resolver = FunqDependencyResolver
});
}
}
}