using Infrastructure; using MediatR; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Models; using Pomelo.EntityFrameworkCore.MySql; using Pomelo.EntityFrameworkCore.MySql.Infrastructure; using QRCodeService.Application.Behaviors; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; namespace QRCodeService { 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. public void ConfigureServices(IServiceCollection services) { //提供等待界面优化用户体验 services.AddControllersWithViews(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "QRCodeService", Version = "v1" }); }); //MediatR services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidatorBehavior<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(TransactionBehaviour<,>)); //EFCore services.AddDbContextPool( dbContextOptions => dbContextOptions .UseMySql( "server=localhost;user=root;password=root;database=qrcode", // For common usages, see pull request #1233. new MariaDbServerVersion(new Version(10, 5, 9)), // use MariaDbServerVersion for MariaDB mySqlOptions => mySqlOptions .CharSetBehavior(CharSetBehavior.NeverAppend)) // Everything from this point on is optional but helps with debugging. .EnableSensitiveDataLogging() .EnableDetailedErrors() ); } // 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(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "QRCodeService v1")); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); } } }