Skip to content

Instantly share code, notes, and snippets.

@kwanann
Created February 23, 2016 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwanann/7bced8e22fec229bd0be to your computer and use it in GitHub Desktop.
Save kwanann/7bced8e22fec229bd0be to your computer and use it in GitHub Desktop.
Sample startup.cs
public class Startup
{
public Startup(IHostingEnvironment env, IApplicationEnvironment env2)
{
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddSingleton<ITestDependencyInjection, MyTestDependencyInjection>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.Use(async (ctx, next) =>
{
ITestDependencyInjection testdi = ctx.ApplicationServices.GetService<ITestDependencyInjection>();
Console.WriteLine("App.use -0 before next: " + testdi.GetAndIncrementCounter());
await next();
Console.WriteLine("App.use - after next: " + testdi.GetAndIncrementCounter());
});
app.UseMvc();
}
// Entry point for the application.
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment