-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
91 lines (64 loc) · 2.81 KB
/
Copy pathProgram.cs
File metadata and controls
91 lines (64 loc) · 2.81 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
using BookWebApp.Data;
using BookWebApp.Manager.Abstract;
using BookWebApp.Manager.Concrete;
using BookWebApp.Models;
using BookWebApp.Repositories.Abstract;
using BookWebApp.Repositories.Concrete;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
string strConn = builder.Configuration.GetConnectionString("ConnStr");
builder.Services.AddDbContext<AppDbContext>(x => x.UseSqlServer(strConn));
builder.Services
.AddIdentity<AppUser, AppRole>(x => x.SignIn.RequireConfirmedEmail = false)
.AddEntityFrameworkStores<AppDbContext>()
.AddRoles<AppRole>();
//builder.Services.AddTransient<IBookManager, BookManager>();
//builder.Services.AddScoped<IBookManager>();
builder.Services.AddScoped<IBookRepository, BookRepository>();
builder.Services.AddScoped<IBookManager, BookManager>();
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
builder.Services.AddScoped<ICategoryManager, CategoryManager>();
builder.Services.AddScoped<IAuthorRepository, AuthorRepository>();
builder.Services.AddScoped<IAuthorManager, AuthorManager>();
builder.Services.AddScoped<IPublisherRepository, PublisherRepository>();
builder.Services.AddScoped<IPublisherManager, PublisherManager>();
builder.Services.AddScoped<IReviewRepository, ReviewRepository>();
builder.Services.AddScoped<IReviewManager, ReviewManager>();
// JSon verilerini çekerken property isimlerinin ilk harflerini lowercase yapýyor, bunu disable etmek için:
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null; // Varsayýlan küçük harfle baþlamayý kapatýr
});
// Yetkisiz eriþim için özel bir sayfa eklemek için
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Home/UnAuthorized"; // Giriþ yapýlmamýþsa buraya yönlendirme yapar (Login ekranýna gitmesini istemedik)
options.AccessDeniedPath = "/Home/UnAuthorized"; // Yetkisiz eriþimlerde yönlendirme yapýlacak sayfa
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error"); // 500 Hatalarý için
app.UseStatusCodePagesWithReExecute("/Home/Error", "?code={0}"); // 404 dahil tüm durum kodlarý için
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
// Area'larý etkinleþtirmek için
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
);
});
// 404 sayfasýný URL deðiþtirmeden göstermek için
app.UseStatusCodePagesWithReExecute("/Home/NotFound");
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();