Description
Recently I used LighInject to replace SignalR DependencyResolver
. Unfortunately, I had some issues and those could have been avoided with better documentation.
Basic Information
Using the following Nuget Packages:
- LightInject.Source 4.0.0.0
- LightInject.SignalR.Source 1.0.0.1
- LightInject.Interception.Source 1.0.0.8
First thing
The documentation exhibits a method that does not actually exists: serviceContainer.RegisterHubs()
;
Second thing
If you use the documented way of integrating LightInject in SignalR, the serviceContainer.EnableSignalR()
method only replaces the DependencyResolver
within the HubConfiguration
and not within the GlobalHost
. Therefore, if you want to use a hub outside of its context using GlobalHost.ConnectionManager.GetHubContext<myHub>()
, the returned hub will be different and you won't be able to communicate with the clients.
The following StackOverflow question explains better the issues I encountered.
Finally
#212 is a pull request to fix the missing dependency within the LightInject.SignalR Nuget package. Also, when using the "non-source" nugets, for the LightInject.SignalR Nuget package to work with its dependency (LightInject.Interception), you need to add an explicit call to the library for it to be outputed in your binaries. Otherwise the library won't work. Ex.:
public class AgentManagementStartup
{
public void ConfigurationOwin(IAppBuilder app, IAgentManagerDataStore dataStore)
{
var serializer = new JsonSerializer
{
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
TypeNameHandling = TypeNameHandling.Auto,
TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple
};
// DO NOT REMOVE ==> Explicit usage of LightInject.Interception for the DLL to
// be included in the output
// ReSharper disable once UnusedVariable
var includLightInjectInterceptionByExplicitUsage = new MethodSelector();
var container = new ServiceContainer();
container.RegisterInstance(dataStore);
container.RegisterInstance(serializer);
container.Register<EventHub>();
container.Register<ManagementHub>();
var config = container.EnableSignalR();
GlobalHost.DependencyResolver = config.Resolver;
GlobalHost.HubPipeline.AddModule(new LoggingPipelineModule());
app.MapSignalR("", config);
}
}
If there is any way I could help with those issues, please indicate how 👍
CC: @cstlaurent