Sieve/Sieve.Sample/Startup.cs
ITDancer139 428acd7558 * Migrate tests to xunit
* Update sample project to dotnetcore3.1
* Use Sqlite in sample project to run it everywhere
* Fix: Filter with escaped comma
* Fix: Filter "null" does not work with Contains or StartsWith
* Code cleanup: Adjust namespaces, adjust usings
2021-05-13 14:04:18 +02:00

61 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Sieve.Models;
using Sieve.Sample.Entities;
using Sieve.Sample.Services;
using Sieve.Services;
namespace Sieve.Sample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(opts =>
{
opts.EnableEndpointRouting = false;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite("Data Source=.\\sieve.db"));
services.Configure<SieveOptions>(Configuration.GetSection("Sieve"));
services.AddScoped<ISieveCustomSortMethods, SieveCustomSortMethods>();
services.AddScoped<ISieveCustomFilterMethods, SieveCustomFilterMethods>();
services.AddScoped<ISieveProcessor, ApplicationSieveProcessor>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
PrepareDatabase(app);
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseMvc();
}
private static void PrepareDatabase(IApplicationBuilder app)
{
using var scope = app.ApplicationServices.CreateScope();
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
dbContext.Database.EnsureDeleted();
dbContext.Database.Migrate();
}
}
}