106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using AntDesign.ProLayout;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using UserPointManagement.Application;
|
|
using UserPointManagement.Persistence;
|
|
|
|
namespace UserPointManagement.Web
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddControllers(options =>
|
|
{
|
|
options.UseGeneralRoutePrefix("/api");
|
|
});
|
|
services.AddEndpointsApiExplorer();
|
|
services.AddSwaggerGen(options =>
|
|
{
|
|
Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.xml").ToList().ForEach(file =>
|
|
{
|
|
options.IncludeXmlComments(file, true);
|
|
});
|
|
});
|
|
services.AddRouting(options => options.LowercaseUrls = true);
|
|
|
|
services.AddRazorPages();
|
|
services.AddServerSideBlazor();
|
|
services.AddAntDesign();
|
|
|
|
services.AddDbContextFactory<UserPointManagementDbContext>(option =>
|
|
{
|
|
option.UseNpgsql(Configuration["Connection:UserPointManagement"])
|
|
.UseSnakeCaseNamingConvention();
|
|
});
|
|
|
|
services.AddServices();
|
|
services.AddRepositories();
|
|
services.AddScoped(sp => new HttpClient
|
|
{
|
|
BaseAddress = new Uri(sp.GetService<NavigationManager>().BaseUri)
|
|
});
|
|
services.Configure<ProSettings>(Configuration.GetSection("ProSettings"));
|
|
|
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
|
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
|
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
app.UseSwagger(o =>
|
|
{
|
|
// o.RouteTemplate = $"/api/swagger/{{documentName}}/swagger.json";
|
|
});
|
|
app.UseSwaggerUI(c =>
|
|
{
|
|
// c.RoutePrefix = $"/api/swagger";
|
|
// c.SwaggerEndpoint($"/api/swagger/v1/swagger.json",
|
|
// "UserPointManagement.Api API V1");
|
|
});
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
// 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.UseHttpsRedirection();
|
|
app.UseStaticFiles();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapControllers();
|
|
endpoints.MapBlazorHub();
|
|
endpoints.MapFallbackToPage("/_Host");
|
|
});
|
|
}
|
|
}
|
|
}
|