Skip to content

Commit 303cc04

Browse files
authored
Merge pull request #27 from brandondahler/bugfix/Initialization
Make initialization of bootstraper a startup task instead of a per-request task.
2 parents 14fc90d + 31af169 commit 303cc04

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/Ninject.Web.Common.OwinHost/OwinAppBuilderExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919

2020
namespace Ninject.Web.Common.OwinHost
2121
{
22-
using System;
23-
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Threading.Tasks;
25+
2426
using Owin;
2527

2628
/// <summary>
@@ -51,7 +53,10 @@ public static IAppBuilder UseNinjectMiddleware(this IAppBuilder app, Func<IKerne
5153

5254
app.Properties.Add(NinjectOwinBootstrapperKey, bootstrapper);
5355

54-
return app.Use(bootstrapper.Execute);
56+
57+
var middleware = new Func<Func<IDictionary<string, object>, Task>, Func<IDictionary<string, object>, Task>>(bootstrapper.Execute);
58+
59+
return app.Use(middleware);
5560
}
5661
}
5762
}

src/Ninject.Web.Common.OwinHost/OwinBootstrapper.cs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,17 @@ public OwinBootstrapper(Func<IKernel> createKernel)
6363
this.createKernel = createKernel;
6464
}
6565

66-
/// <summary>
67-
/// The execute.
68-
/// </summary>
69-
/// <param name="context">
70-
/// The context.
71-
/// </param>
72-
/// <param name="next">
73-
/// The next.
74-
/// </param>
66+
/// <summary>
67+
/// The execute.
68+
/// </summary>
69+
/// <param name="next">The next.</param>
7570
/// <returns>
76-
/// The <see cref="Task"/>.
71+
/// The <see cref="Func{IDictionary{string, object}, Task}"/>.
7772
/// </returns>
78-
public async Task Execute(IOwinContext context, Func<Task> next)
79-
{
80-
if (this.bootstrapper == null)
81-
{
73+
public Func<IDictionary<string, object>, Task> Execute(Func<IDictionary<string, object>, Task> next)
74+
{
75+
if (this.bootstrapper == null)
76+
{
8277
lock (this.modules)
8378
{
8479
if (this.bootstrapper == null)
@@ -88,13 +83,15 @@ public async Task Execute(IOwinContext context, Func<Task> next)
8883
this.bootstrapper = initializingBootstrapper;
8984
}
9085
}
91-
}
86+
}
9287

93-
using (var scope = new OwinRequestScope())
94-
{
95-
context.Set(NinjectOwinRequestScope, scope);
96-
await next();
97-
}
88+
return async (context) => {
89+
using (var scope = new OwinRequestScope())
90+
{
91+
context[NinjectOwinRequestScope] = scope;
92+
await next(context);
93+
}
94+
};
9895
}
9996

10097
/// <summary>

0 commit comments

Comments
 (0)