-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (100 loc) · 3.96 KB
/
Program.cs
File metadata and controls
111 lines (100 loc) · 3.96 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
global using AspDotNetCoreEmpty.ViewModels;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Http;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Mvc.RazorPages;
global using Microsoft.AspNetCore.Razor.TagHelpers;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.Hosting;
global using System;
global using System.Collections.Generic;
global using System.Linq;
using AspDotNetCoreEmpty.Models;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Identity;
namespace AspDotNetCoreEmpty;
public class Program
{
const string conStr = "ConnectionStrings:BethanysPieShopDbContextConnection";
[Obsolete("Just don't use it")]
static void DumbTestsArea()
{
Dictionary<string, float> studentsHeights= new()
{
["Stephen"] = 183,
["Jennifer"] = 159,
["Susanne"] = 165,
["Joe"] = 160
};
throw new ExecutionEngineException("This is a playground method, don't use it");
}
public static void Main(string[] args)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
string connectionString = builder.Configuration.GetConnectionString("BethanysPieShopDbContextConnection") ?? throw new InvalidOperationException("Connection string 'BethanysPieShopDbContextConnection' not found.");
builder.Services
.AddDbContext<BethanysPieShopDbContext>(
options => options.UseSqlServer(connectionString))
.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<BethanysPieShopDbContext>();
builder.Services.AddRazorPages();
builder.Services.AddRazorComponents(options => options.DetailedErrors = builder.Environment.IsDevelopment());
builder.Services
.AddScoped<ICategoryRepository, CategoryRepository>()
.AddScoped<IPieRepository, PieRepository>()
.AddScoped<IOrderRepository, OrderRepository>()
.AddScoped<IShoppingCart, ShoppingCart>(sp => ShoppingCart.GetCart(sp))
.AddSession()
.AddSingleton<IHttpContextAccessor, HttpContextAccessor>()
.AddHttpContextAccessor()
.AddDbContext<BethanysPieShopDbContext>(options =>
{
options.UseSqlServer(builder.Configuration[conStr]);
})
.AddDatabaseDeveloperPageExceptionFilter()
.AddControllersWithViews()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
});
WebApplication app = builder.Build();
app
.UseStaticFiles()
.UseSession()
.UseAuthentication()
.UseAntiforgery()
.UseHttpsRedirection()
.UseAuthorization();
if(app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
app.UseExceptionHandler("/Error");
}
app.MapDefaultControllerRoute();
app.MapRazorPages();
//app.MapControllerRoute("default1", "{controller=Homet}/{action=Index}/{id?}");
//DbInitializer.Seed(app);
app.Run();
}
/*/// <summary>
/// Debug attempt
/// </summary>
/// <param name="text">text to print out</param>
[Conditional("debug")]
public static void WriteColorLine(string text)
{
var currentBgColor = Console.BackgroundColor;
var currentTextColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Blue;
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine(text);
Console.ForegroundColor = currentTextColor;
Console.BackgroundColor = currentBgColor;
}*/
}