-
Notifications
You must be signed in to change notification settings - Fork 7
/
RegistrationExtensions.cs
32 lines (28 loc) · 1.06 KB
/
RegistrationExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using Autofac;
using Autofac.Builder;
using Microsoft.AspNet.SignalR;
namespace SignalR.Autofac
{
public static class RegistrationExtensions
{
public static IRegistrationBuilder<AutofacDependencyResolver, SimpleActivatorData, SingleRegistrationStyle> RegisterDependencyResolver(this ContainerBuilder builder)
{
var rb = GetBuilder();
builder.RegisterCallback(cr =>
{
var source = new AutofacDependencyResolver();
var registration = rb.CreateRegistration();
cr.Register(registration);
cr.AddRegistrationSource(source);
});
return rb;
}
private static IRegistrationBuilder<AutofacDependencyResolver, SimpleActivatorData, SingleRegistrationStyle> GetBuilder()
{
return RegistrationBuilder.ForDelegate((ctx, param) => new AutofacDependencyResolver(ctx.Resolve<ILifetimeScope>()))
.As<IDependencyResolver>()
.InstancePerLifetimeScope();
}
}
}