/
Program.cs
45 lines (36 loc) · 1.48 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
using CarShopCourseWork.Db;
using CarShopCourseWork.Model.data;
using CarShopCourseWork.Model.Data;
using CarShopCourseWork.Model.interfaces;
using CarShopCourseWork.Model.Repository;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
var services = builder.Services;
services.AddTransient<IMakeRepository, DataMakeRepository>();
services.AddTransient<ICarRepository, DataCarRepository>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped(sp => ShoppingCart.GetCart(sp, "Model/DataStore/ShoppingCart.json"));
services.AddTransient<List<Order>>();
services.AddTransient<List<OrderDetail>>();
services.AddTransient<IOrderRepository, DataOrderRepository>();
services.AddMvc();
services.AddSession();
var connectionString = builder.Configuration.GetConnectionString("MySqlConnection");
ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
services.AddDbContext<CarDbContext>(options => options.UseMySql(connectionString, serverVersion));
var app = builder.Build();
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseStaticFiles();
app.UseSession();
app.UseRouting();
app.MapControllerRoute(
name: "countryfilter",
pattern: "Car/{action}/{make?}",
defaults: new { Controller = "Car", action = "List" });
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{Id?}");
app.Run();