-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (29 loc) · 1.12 KB
/
Copy pathProgram.cs
File metadata and controls
42 lines (29 loc) · 1.12 KB
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
using Microsoft.EntityFrameworkCore;
using PsCoreDemo.Data;
using PsCoreDemo.Repository;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// builder.Services.AddScoped - ** Use this the most **
// creates single instance per request and will be disposed at the end of the request
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
builder.Services.AddScoped<ICardRepository, CardRepository>();
builder.Services.AddScoped<IBookRepository, BookRepository>();
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<MarketShopDbContext>(options =>
options.UseSqlite(builder.Configuration.GetConnectionString("MarketShopDbContextConnection"))
);
var app = builder.Build();
app.UseStaticFiles();
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// Seed the database with initial data
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<MarketShopDbContext>();
MarketSeedDbInitializer.Seed(context);
}
app.MapDefaultControllerRoute();
app.Run();