Skip to content

How to make it work (without issues at resolving) #3

Description

@hidegh

So, it's a nice solution, but making DI work was a pain. Found 2 good links:

Anyhow the solution is here...

**AutofacWebctivator**

			// Need to register SignalR Hubs (and special LifetimeHubManager too)!
			builder.RegisterLifetimeHubManager();
			builder.RegisterType<ExportPacketHub>().ExternallyOwned();

			//
			// SignalR MAGIC CODE for DI!
			builder.RegisterType<Autofac.Integration.SignalR.AutofacDependencyResolver>()
				.As<Microsoft.AspNet.SignalR.IDependencyResolver>()
				.SingleInstance();

			builder.Register(context =>
				context
					.Resolve<Microsoft.AspNet.SignalR.IDependencyResolver>()
					.Resolve<Microsoft.AspNet.SignalR.Infrastructure.IConnectionManager>()
					.GetHubContext<ExportPacketHub>()
				)
				.ExternallyOwned();


			//
			// ...
			container = builder.Build();
**Startup.cs**

			// Grab container
			var container = AutofacWebActivator.Container;

			// Get your HubConfiguration. In OWIN, we create one rather than using GlobalHost
			var hubConfig = new HubConfiguration();

			// Sets the dependency resolver to be autofac (WITHOUT CONTAINERBUILDER UPDATE)...
			hubConfig.Resolver = container.Resolve<Microsoft.AspNet.SignalR.IDependencyResolver>();

			// OWIN SIGNALR SETUP: register the Autofac middleware FIRST, then the standard SignalR middleware.
			app.UseAutofacMiddleware(container);
			app.MapSignalR("/signalr", hubConfig);

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions