-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutofacBootstrapper.cs
53 lines (45 loc) · 1.67 KB
/
AutofacBootstrapper.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
namespace Nancy.Bootstrappers.Autofac
{
using global::Autofac;
using global::Autofac.Core.Lifetime;
using Nancy.Core;
using Nancy.Core.Http;
using Nancy.Core.Registration;
public class AutofacBootstrapper : Bootstrapper<ContainerBuilder, ILifetimeScope>
{
protected sealed override ContainerBuilder CreateBuilder()
{
return new ContainerBuilder();
}
protected sealed override void Register(ContainerBuilder builder, IContainerRegistry registry)
{
builder.Register(registry);
}
protected sealed override ILifetimeScope BuildContainer(ContainerBuilder builder)
{
return builder.Build();
}
protected sealed override void ValidateContainerConfiguration(ILifetimeScope container)
{
// Not supported.
}
protected sealed override IApplication<ILifetimeScope> CreateApplication(Disposable<ILifetimeScope> lifetimeScope)
{
return new Application(lifetimeScope);
}
private sealed class Application : Application<ILifetimeScope>
{
public Application(Disposable<ILifetimeScope> lifetimeScope) : base(lifetimeScope)
{
}
protected override ILifetimeScope BeginRequestScope(HttpContext context, ILifetimeScope lifetimeScope)
{
return lifetimeScope.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag);
}
protected override IEngine ComposeEngine(ILifetimeScope lifetimeScope)
{
return lifetimeScope.Resolve<IEngine>();
}
}
}
}