Skip to content

Commit 08fda18

Browse files
committed
Issue #1 - Removing the check to stop multiple Autofac middleware registrations.
1 parent c3d06b0 commit 08fda18

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/Autofac.Integration.Owin/AutofacAppBuilderExtensions.cs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,6 @@ public static IAppBuilder UseAutofacLifetimeScopeInjector(this IAppBuilder app,
132132
throw new ArgumentNullException("container");
133133
}
134134

135-
if (app.Properties.ContainsKey(InjectorRegisteredKey))
136-
{
137-
return app;
138-
}
139-
140135
return app.RegisterAutofacLifetimeScopeInjector(container);
141136
}
142137

@@ -189,11 +184,6 @@ public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeSc
189184
throw new ArgumentNullException("container");
190185
}
191186

192-
if (app.Properties.ContainsKey(InjectorRegisteredKey))
193-
{
194-
return app;
195-
}
196-
197187
return app
198188
.RegisterAutofacLifetimeScopeInjector(container)
199189
.UseAllMiddlewareRegisteredInContainer(container);
@@ -254,16 +244,16 @@ public static IAppBuilder UseMiddlewareFromContainer<T>(this IAppBuilder app)
254244
private static IAppBuilder RegisterAutofacLifetimeScopeInjector(this IAppBuilder app, ILifetimeScope container)
255245
{
256246
app.Use(async (context, next) =>
257-
{
258-
using (var lifetimeScope = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag,
247+
{
248+
using (var lifetimeScope = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag,
259249
b => b.RegisterInstance(context).As<IOwinContext>()))
260-
{
261-
context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope);
262-
await next();
263-
}
264-
});
250+
{
251+
context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope);
252+
await next();
253+
}
254+
});
265255

266-
app.Properties.Add(InjectorRegisteredKey, true);
256+
app.Properties[InjectorRegisteredKey] = true;
267257
return app;
268258
}
269259

0 commit comments

Comments
 (0)