-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
156 lines (125 loc) · 4.91 KB
/
Copy pathProgram.cs
File metadata and controls
156 lines (125 loc) · 4.91 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using Microsoft.EntityFrameworkCore;
using SportsClub.Models;
using SportsClub.DataTransferObjects;
using AutoMapper;
using SportsClub.Models.Repositores;
using SportsClub.Core.Requests;
using SportsClub.Core.Pagination.Services;
using SportsClub.Extensions;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using System.Text;
using SportsClub.Core.Payments;
using SportsClub.Controllers;
using SportsClub.Core.Services;
using Microsoft.AspNetCore.SpaServices.AngularCli;
var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddHttpContextAccessor();
// Add services to the container.
builder.Services.AddAutoMapper(typeof(Program));
//builder.Services.AddControllersWithViews();
builder.Services.AddCors();
var mappingConfig = new MapperConfiguration(mc =>
{
mc.AddProfile(new MappingProfile());
// mc.AddProfile<UserDto>();
});
IMapper mapper = mappingConfig.CreateMapper();
builder.Services.AddScoped<IRepositoryBase<UserSubscription>, UserSubscriptionRepostry>();
builder.Services.AddScoped<IRepositoryBase<PaymentGatway>, PaymentGatwayRepostry>();
builder.Services.AddScoped<IRepositoryBase<UserSubscriptionService>, UserSubscriptionServicesRepostry>();
builder.Services.AddScoped<IRepositoryBase<ServiceType>, ServiceTypeRepostry>();
builder.Services.AddScoped<IRepositoryBase<ServiceTime>, ServiceTimeRepostry>();
builder.Services.AddScoped<IRepositoryBase<Service>, ServiceRepostry>();
builder.Services.AddScoped<IRepositoryBase<UserDetail>, UserDetailRepostry>();
builder.Services.AddScoped<IRepositoryBase<User>, UserRepostry>();
builder.Services.AddScoped<IUserAuthenticationRepository, UserAuthenticationRepository>();
builder.Services.AddDbContext<SportsClubContext>(options =>
{
options.UseSqlServer(builder.Configuration.GetConnectionString("SqlCon2022"));
});
builder.Services.AddHttpContextAccessor();
builder.Services.AddSingleton<IUriService>(o =>
{
var accessor = o.GetRequiredService<IHttpContextAccessor>();
var request = accessor.HttpContext.Request;
var uri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent());
return new UriService(uri);
});
builder.Services.AddCors();
builder.Services.AddControllers().AddNewtonsoftJson(x =>
x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);
//SecretClient keyVaultClient = new SecretClient(
// new Uri(_configuration.GetValue<string>("KeyVaultUri")),
// new DefaultAzureCredential());
//authenticationConfiguration.AccessTokenSecret = keyVaultClient.GetSecret("access-token-secret").Value.Value;
builder.Services.AddAuthentication();
builder.Services.ConfigureIdentity();
builder.Services.ConfigureJWT(builder.Configuration);
AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
//_configuration.Bind("Authentication", authenticationConfiguration);
var assembly = typeof(Program).Assembly; ;
/*
builder.Services.AddMvc().AddControllersAsServices();*/
builder.Services.AddControllersWithViews();
builder.Services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
builder.Services
.AddControllers()
.AddApplicationPart(assembly)
.AddFluentValidation(config =>
{
config.RegisterValidatorsFromAssembly(typeof(ServiceRequest).Assembly);
config.RegisterValidatorsFromAssembly(typeof(UserSubscriptionRequest).Assembly);
})
.AddControllersAsServices();
// paypal client configuration
/*builder.Services.AddSingleton(x =>
new PaypalClient(
builder.Configuration["PayPalOptions:ClientId"],
builder.Configuration["PayPalOptions:ClientSecret"],
builder.Configuration["PayPalOptions:Mode"]
)
);*/
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseExceptionHandler("/Home/Error");
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
//app.UseCors(MyAllowSpecificOrigins);
app.UseSpaStaticFiles();
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(x => x.MapControllers());
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (app.Environment.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
app.MapFallbackToFile("index.html"); ;
app.Run();