using Back; using Back.Data.Contracts; using Back.Data.Infrastructure.Repository; using Back.Features; using Back.Services; using Back.Services.Warehouse; using Back.Validations; using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Microsoft.Net.Http.Headers; using Microsoft.OpenApi.Models; using System.Text; using TaxPayer.Infrastructure.Persistence; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(option => { option.SwaggerDoc("v1", new OpenApiInfo { Title = "TaxPayer API", Version = "Preview" }); option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { In = ParameterLocation.Header, Description = "Please enter a valid token", Name = "Authorization", Type = SecuritySchemeType.Http, BearerFormat = "JWT", Scheme = "Bearer" }); option.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type=ReferenceType.SecurityScheme, Id="Bearer" } }, new string[]{} } }); }); builder.Services.AddDbContext(options => { options.UseSqlServer(builder.Configuration.GetConnectionString("Base")); }); builder.Services.AddScoped(typeof(IAsyncRepository<>), typeof(RepositoryBase<>)); builder.Services.AddScoped(typeof(RepositoryBase<>), typeof(RepositoryBase<>)); builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped(); builder.Services.AddScoped (); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2")); string origins = "OriginTaxPayer"; builder.Services.AddCors(options => { options.AddPolicy(origins, policy => { policy.WithOrigins("https://localhost:7224", "http://localhost:5107" , "http://195.88.208.142", "http://moadiran.ir" , "https://195.88.208.142", "https://moadiran.ir" , "https://195.88.208.142:440", "https://moadiran.ir:440", "https://localhost:44346") .AllowAnyHeader() .WithHeaders(HeaderNames.ContentType) .AllowAnyMethod(); }); }); #region JWT builder.Services.AddAuthentication("Bearer") .AddJwtBearer(options => { options.TokenValidationParameters = new() { ValidateIssuer = true, ValidateAudience = true, ValidateIssuerSigningKey = true, ValidIssuer = Fixedvalues.Issuer, ValidAudience = Fixedvalues.Audience, IssuerSigningKey = new SymmetricSecurityKey( Encoding.ASCII.GetBytes(Fixedvalues.SecretForKey)) }; } ); #endregion var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseCors(origins); app.UseAuthentication(); app.UseAuthorization(); app.UseCheckOnlineUser(); app.MapControllers(); app.Run();