You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
103 lines
3.4 KiB
103 lines
3.4 KiB
using API;
|
|
using API.Service;
|
|
using Asp.Versioning;
|
|
using DbContextLib;
|
|
using DbDataManager.Service;
|
|
using Dto;
|
|
using Entities;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.OpenApi.Models;
|
|
using Shared;
|
|
|
|
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();
|
|
|
|
//builder.Services.AddScoped<IUserService<UserEntity>, DbDataManager.Service.UserDataService>();
|
|
//builder.Services.AddScoped<IUserDataService, Shared.UserDataService>();
|
|
builder.Services.AddScoped<IdataService<UserDTO, LessonDTO, InquiryDTO, ParagraphDTO, SuccessDTO>, DataService<UserDTO, LessonDTO, InquiryDTO, ParagraphDTO, SuccessDTO>>();
|
|
|
|
builder.Services.AddScoped<IUserService<UserEntity>, UserDataService>();
|
|
builder.Services.AddScoped<IUserService<UserDTO>, UserDataServiceApi>();
|
|
|
|
builder.Services.AddScoped<IInquiryService<InquiryEntity>, InquiryDataService>();
|
|
builder.Services.AddScoped<IInquiryService<InquiryDTO>, InquiryDataServiceApi>();
|
|
|
|
builder.Services.AddScoped<IParagraphService<ParagraphEntity>, ParagraphDataService>();
|
|
builder.Services.AddScoped<IParagraphService<ParagraphDTO>, ParagraphDataServiceApi>();
|
|
|
|
builder.Services.AddScoped<ISuccessService<SuccessEntity>, SuccessDataService>();
|
|
builder.Services.AddScoped<ISuccessService<SuccessDTO>, SuccessDataServiceApi>();
|
|
|
|
builder.Services.AddScoped<ILessonService<LessonEntity>, LessonDataService>();
|
|
builder.Services.AddScoped<ILessonService<LessonDTO>, LessonDataServiceApi>();
|
|
|
|
builder.Services.AddDbContext<DbContext, UserDbContext>();
|
|
builder.Services.AddDbContext<WebAPIDbContext>(options => options.UseInMemoryDatabase("appDb"));
|
|
builder.Services.AddIdentityApiEndpoints<IdentityUser>().AddEntityFrameworkStores<WebAPIDbContext>();
|
|
builder.Services.AddAuthorization();
|
|
builder.Services.AddApiVersioning(o =>
|
|
{
|
|
o.AssumeDefaultVersionWhenUnspecified = true;
|
|
o.DefaultApiVersion = new ApiVersion(1);
|
|
o.ReportApiVersions = true;
|
|
}).AddApiExplorer(
|
|
options =>
|
|
{
|
|
options.GroupNameFormat = "'v'VVV";
|
|
options.SubstituteApiVersionInUrl = true;
|
|
});
|
|
//builder.Services.AddIdentityApiEndpoints<IdentityUser>()
|
|
// .AddEntityFrameworkStores<UserDbContext>();
|
|
builder.Services.AddSwaggerGen(option =>
|
|
{
|
|
option.SwaggerDoc("v1", new OpenApiInfo { Title = "Demo API", Version = "v1" });
|
|
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[] { }
|
|
}
|
|
});
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.MapIdentityApi<IdentityUser>();
|
|
|
|
app.Run(); |