-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
55 lines (40 loc) · 1.46 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Microsoft.EntityFrameworkCore;
using Library.Models;
using Microsoft.OpenApi.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
//using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<DataContext>(opts =>
{
opts.UseSqlServer(builder.Configuration["ConnectionStrings:BookShelveConnection"]);
opts.EnableSensitiveDataLogging(true);
});
builder.Services.AddControllers().AddNewtonsoftJson();
builder.Services.AddControllersWithViews();
builder.Services.AddScoped<IBookRepo,EBookRepo>();
builder.Services.AddScoped<ICategoryRepo,ECategoryRepo>();
//Omit Null Values
builder.Services.Configure<MvcNewtonsoftJsonOptions>(options =>{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
});
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Library", Version = "v1" });
});
builder.Services.AddHttpClient();
var app = builder.Build();
app.MapControllers();
app.MapDefaultControllerRoute();
//app.MapControllerRoute("Default", "{controller = Home}/{action=Index}/{id?}");
app.UseMiddleware<Library.TestMiddleware>();
app.UseStaticFiles();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Library");
});
//app.MapGet("/", () => "Hello World!");
var context = app.Services.CreateScope().ServiceProvider.GetRequiredService<DataContext>();
SeedData.SeedDatabase(context);
app.Run();