public static AddMiddleware UseBuilder(this AddMiddleware app, Action <IApplicationBuilder> pipeline) { var builder = app.UseBuilder(); pipeline(builder); return(app); }
public async Task OwinDefaultNullServiceProvider() { var list = new List <CreateMiddleware>(); AddMiddleware build = list.Add; IServiceProvider serviceProvider = null; FakeService fakeService = null; bool builderExecuted = false; bool applicationExecuted = false; var builder = build.UseBuilder(applicationBuilder => { builderExecuted = true; serviceProvider = applicationBuilder.ApplicationServices; applicationBuilder.Run(context => { applicationExecuted = true; fakeService = context.RequestServices.GetService <FakeService>(); return(Task.FromResult(0)); }); }); list.Reverse(); await list .Aggregate(notFound, (next, middleware) => middleware(next)) .Invoke(new Dictionary <string, object>()); Assert.True(builderExecuted); Assert.NotNull(serviceProvider); Assert.True(applicationExecuted); Assert.Null(fakeService); }
public static IApplicationBuilder UseBuilder(this AddMiddleware app, IServiceProvider serviceProvider) { if (app == null) { throw new ArgumentNullException(nameof(app)); } // Do not set ApplicationBuilder.ApplicationServices to null. May fail later due to missing services but // at least that results in a more useful Exception than a NRE. if (serviceProvider == null) { serviceProvider = new EmptyProvider(); } // Adapt WebSockets by default. app(OwinWebSocketAcceptAdapter.AdaptWebSockets); var builder = new ApplicationBuilder(serviceProvider: serviceProvider); var middleware = CreateMiddlewareFactory(exit => { builder.Use(ignored => exit); return(builder.Build()); }, builder.ApplicationServices); app(middleware); return(builder); }
public async Task OwinConfigureServiceProviderAddsServices() { var list = new List <CreateMiddleware>(); AddMiddleware build = list.Add; IServiceProvider serviceProvider = null; FakeService fakeService = null; var builder = build.UseBuilder(applicationBuilder => { serviceProvider = applicationBuilder.ApplicationServices; applicationBuilder.Run(context => { fakeService = context.RequestServices.GetService <FakeService>(); return(Task.FromResult(0)); }); }, new ServiceCollection().AddSingleton(new FakeService()).BuildServiceProvider()); list.Reverse(); await list .Aggregate(notFound, (next, middleware) => middleware(next)) .Invoke(new Dictionary <string, object>()); Assert.NotNull(serviceProvider); Assert.NotNull(serviceProvider.GetService <FakeService>()); Assert.NotNull(fakeService); }
public static IAppBuilder UseBuilder(this IAppBuilder app, IServiceProvider provider, Action <IApplicationBuilder> configuration) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (provider == null) { throw new ArgumentNullException(nameof(provider)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } AddMiddleware add = middleware => { app.Use(new Func <AppFunc, AppFunc>(next => middleware(next))); }; add.UseBuilder(configuration, provider); return(app); }
public static AddMiddleware UseBuilder(this AddMiddleware app, Action <IApplicationBuilder> pipeline, IServiceProvider serviceProvider) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (pipeline == null) { throw new ArgumentNullException(nameof(pipeline)); } var builder = app.UseBuilder(serviceProvider); pipeline(builder); return(app); }
public void Configure(AddMiddleware build) { var services = new ServiceCollection(); services.AddSingleton(new DiagnosticLogger("Owin Diagnostic Logger: ")); // adding vNext component in OWIN pipline build.UseBuilder(appBuilder => { appBuilder.Run(async context => { context.RequestServices.GetService<DiagnosticLogger>().Log("Returning Hello World"); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello World!"); }); }, services.BuildServiceProvider()); }
public static void Configure(AddMiddleware build) { var services = new ServiceCollection(); services.AddSingleton(new DiagnosticLogger("Owin Diagnostic Logger: ")); // adding vNext component in OWIN pipline build.UseBuilder(appBuilder => { appBuilder.Run(async context => { context.RequestServices.GetService <DiagnosticLogger>().Log("Returning Hello World"); context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("Hello World!"); }); }, services.BuildServiceProvider()); }
public static IApplicationBuilder UseBuilder(this AddMiddleware app) { return(app.UseBuilder(serviceProvider: null)); }
public static AddMiddleware UseBuilder(this AddMiddleware app, Action <IApplicationBuilder> pipeline) { return(app.UseBuilder(pipeline, serviceProvider: null)); }