2021-03-20 14:12:24 +08:00
|
|
|
|
|
2021-03-21 02:13:08 +08:00
|
|
|
|
using Autofac;
|
|
|
|
|
|
using Autofac.Extras.DynamicProxy;
|
2021-03-20 14:12:24 +08:00
|
|
|
|
using CC.Yi.BLL;
|
2021-03-21 15:51:49 +08:00
|
|
|
|
using CC.Yi.Common.Cache;
|
2021-03-21 02:13:08 +08:00
|
|
|
|
using CC.Yi.Common.Castle;
|
2021-03-20 14:12:24 +08:00
|
|
|
|
using CC.Yi.DAL;
|
|
|
|
|
|
using CC.Yi.IBLL;
|
|
|
|
|
|
using CC.Yi.IDAL;
|
|
|
|
|
|
using CC.Yi.Model;
|
|
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
2021-03-25 20:44:12 +08:00
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
2021-03-20 14:12:24 +08:00
|
|
|
|
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 System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace CC.Yi.API
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial 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)
|
|
|
|
|
|
{
|
2021-04-10 18:28:45 +08:00
|
|
|
|
|
2021-03-20 14:12:24 +08:00
|
|
|
|
services.AddControllers();
|
|
|
|
|
|
services.AddSwaggerGen(c =>
|
|
|
|
|
|
{
|
|
|
|
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "CC.Yi.API", Version = "v1" });
|
|
|
|
|
|
});
|
2021-04-10 18:28:45 +08:00
|
|
|
|
services.AddSession();
|
|
|
|
|
|
services.AddMvc();
|
|
|
|
|
|
string connection1 = Configuration["ConnectionStringBySQL"];
|
2021-03-20 14:12:24 +08:00
|
|
|
|
string connection2 = Configuration["ConnectionStringByMySQL"];
|
2021-04-10 18:28:45 +08:00
|
|
|
|
string connection3 = Configuration["ConnectionStringBySQLite"];
|
2021-03-20 14:12:24 +08:00
|
|
|
|
services.AddDbContext<DataContext>(options =>
|
|
|
|
|
|
{
|
2021-04-10 18:28:45 +08:00
|
|
|
|
options.UseSqlServer(connection1, b => b.MigrationsAssembly("CC.Yi.API"));//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
|
2021-03-20 14:12:24 +08:00
|
|
|
|
});
|
2021-03-25 20:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
2021-03-21 02:13:08 +08:00
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>Autofac
|
|
|
|
|
|
//services.AddScoped(typeof(IBaseDal<>), typeof(BaseDal<>));
|
|
|
|
|
|
//services.AddScoped(typeof(IstudentBll), typeof(studentBll));
|
2021-04-10 18:28:45 +08:00
|
|
|
|
|
|
|
|
|
|
//reidsע<73><D7A2>
|
|
|
|
|
|
//services.AddSingleton(typeof(ICacheWriter), new RedisCacheService(new Microsoft.Extensions.Caching.Redis.RedisCacheOptions()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Configuration = Configuration.GetSection("Cache.ConnectionString").Value,
|
|
|
|
|
|
// InstanceName = Configuration.GetSection("Cache.InstanceName").Value
|
|
|
|
|
|
//}));
|
2021-03-25 20:44:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>Identity<74><79><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤
|
2021-04-10 18:28:45 +08:00
|
|
|
|
//services.AddIdentity<result_user, IdentityRole>(options =>
|
|
|
|
|
|
// {
|
|
|
|
|
|
// options.Password.RequiredLength = 6;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD><CCB3><EFBFBD>
|
|
|
|
|
|
// options.Password.RequireDigit = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
// options.Password.RequireLowercase = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сд<D0A1><D0B4>ĸ
|
|
|
|
|
|
// options.Password.RequireNonAlphanumeric = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
|
|
|
|
|
// options.Password.RequireUppercase = false;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>ĸ
|
|
|
|
|
|
// //options.User.RequireUniqueEmail = false;//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Բ<EFBFBD><D4B2>ظ<EFBFBD>
|
|
|
|
|
|
// //options.User.AllowedUserNameCharacters="abcd"//<2F><><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
|
|
|
|
|
|
//}).AddEntityFrameworkStores<DataContext>().AddDefaultTokenProviders();
|
|
|
|
|
|
services.AddCors(options => options.AddPolicy("CorsPolicy",//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
builder =>
|
2021-03-25 20:44:12 +08:00
|
|
|
|
{
|
2021-04-10 18:28:45 +08:00
|
|
|
|
builder.AllowAnyMethod()
|
|
|
|
|
|
.SetIsOriginAllowed(_ => true)
|
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
|
.AllowCredentials();
|
|
|
|
|
|
}));
|
2021-03-21 02:13:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-28 20:56:27 +08:00
|
|
|
|
private void InitData(IServiceProvider serviceProvider)
|
|
|
|
|
|
{
|
|
|
|
|
|
var serviceScope = serviceProvider.GetRequiredService<IServiceScopeFactory>().CreateScope();
|
2021-04-10 18:28:45 +08:00
|
|
|
|
|
|
|
|
|
|
var context = serviceScope.ServiceProvider.GetService<DataContext>();
|
|
|
|
|
|
DbContentFactory.Initialize(context);//<2F><><EFBFBD>þ<EFBFBD>̬<EFBFBD><EFBFBD><E0B7BD>ע<EFBFBD><D7A2>
|
2021-03-28 20:56:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-23 14:27:59 +08:00
|
|
|
|
|
2021-03-20 14:12:24 +08:00
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
|
{
|
2021-04-10 18:28:45 +08:00
|
|
|
|
|
2021-03-20 14:12:24 +08:00
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
|
{
|
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CC.Yi.API v1"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-04-10 18:28:45 +08:00
|
|
|
|
//app.UseAuthentication();
|
|
|
|
|
|
app.UseCors("CorsPolicy");
|
2021-03-20 14:12:24 +08:00
|
|
|
|
app.UseHttpsRedirection();
|
2021-04-10 18:28:45 +08:00
|
|
|
|
app.UseSession();
|
2021-03-20 14:12:24 +08:00
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
|
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
|
{
|
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
|
});
|
2021-03-28 20:56:27 +08:00
|
|
|
|
InitData(app.ApplicationServices);
|
2021-03-20 14:12:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|