Sieve/SieveTests/Startup.cs

68 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.AspNetCore.Builder;
2018-01-27 00:26:37 +01:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
2018-01-27 06:20:57 +01:00
using Microsoft.EntityFrameworkCore;
2018-01-27 00:26:37 +01:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2018-01-27 06:20:57 +01:00
using Sieve.Models;
using Sieve.Services;
using SieveTests.Entities;
2018-01-27 07:37:38 +01:00
using SieveTests.Services;
2018-01-27 00:26:37 +01:00
namespace SieveTests
{
2018-05-15 01:34:37 +02:00
public class Startup
2018-01-27 00:26:37 +01:00
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
2018-01-27 06:20:57 +01:00
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("TestSqlServer")));
2018-01-27 09:30:34 +01:00
services.Configure<SieveOptions>(Configuration.GetSection("Sieve"));
2018-01-27 06:20:57 +01:00
2018-02-07 05:43:09 +01:00
services.AddScoped<ISieveCustomSortMethods, SieveCustomSortMethods>();
services.AddScoped<ISieveCustomFilterMethods, SieveCustomFilterMethods>();
2018-02-10 06:37:04 +01:00
services.AddScoped<ISieveProcessor, ApplicationSieveProcessor>();
2018-01-27 00:26:37 +01:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// TIME MEASUREMENT
var times = new List<long>();
app.Use(async (context, next) =>
{
var sw = new Stopwatch();
sw.Start();
await next.Invoke();
sw.Stop();
times.Add(sw.ElapsedMilliseconds);
var text = $"AVG: {(int)times.Average()}ms; AT {sw.ElapsedMilliseconds}; COUNT: {times.Count()}";
Console.WriteLine(text);
await context.Response.WriteAsync($"<!-- {text} -->");
});
2018-01-27 00:26:37 +01:00
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
}
}