123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Bowin.Common.Cache;
- using Bowin.Common.DES;
- using Bowin.Common.Filters;
- using Bowin.Common.Scheduler;
- using Bowin.Common.ServiceToken;
- using Bowin.Common.Utility;
- using YLShipBuildLandMap.Entity;
- using YLShipBuildLandMap.Entity.ViewModel;
- using YLShipBuildLandMap.Services.SystemSetting;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.StaticFiles;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Caching.Memory;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using Newtonsoft.Json.Serialization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.EntityFrameworkCore.Infrastructure;
- using YLShipBuildLandMap.Entity.Extensions;
- using System.Reflection;
- using Bowin.Common.ServiceToken.ApiIdentity;
- namespace YLShipBuildLandMap.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.
- public void ConfigureServices(IServiceCollection services)
- {
- ServiceConfiguration.RegistLocalServices(services);
- services.AddDbContext<YLShipBuildLandMapContext>(options =>
- options.UseSqlServer(Configuration.GetConnectionString("DataContext"), builder =>
- {
- /*builder.UseRowNumberForPaging();
- */
- })
- ).AddScoped<YLShipBuildLandMapContext>();
- services.AddServiceAssembly(Assembly.Load("YLShipBuildLandMap.Services"), Assembly.Load("YLShipBuildLandMap.IServices"));
- //services.BuildServiceProvider();
- services.UseCache<MemoryCacheProvider>();
- //配置缓存为3分钟
- services.AddOptions().Configure<MemoryCacheEntryOptions>(Configuration.GetSection(nameof(MemoryCacheEntryOptions)))
- .Configure<MemoryCacheEntryOptions>(op =>
- {
- //op.SlidingExpiration = TimeSpan.FromMinutes(3);
- op.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1);
- });
- services.AddBowinAuthentication<LoginUser>(x => HttpHelper.GetService<IUserService>().GetLoginUserById(x),
- x => HttpHelper.GetService<IFunctionCodeService>().GetUserFunctionCodes(x));
- services.AddQuartz();
- services.AddControllers(configure => {
- configure.Filters.Add(typeof(CustomerExceptionFilter));
- })
- .AddNewtonsoftJson(options => {
- options.SerializerSettings.ContractResolver = new DefaultContractResolver();
- options.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
- options.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
- });
- //services.AddSingleton<IDesAccessor, DesAccessor>();
- services.UseBowinDes();
- services.AddApiIdentity<YLShipBuildLandMap.Services.SystemSetting.ISystemService>();
- //允许一个或多个来源可以跨域
- /*services.AddCors(options =>
- {
- options.AddPolicy("CustomCorsPolicy", policy =>
- {
- // 设定允许跨域的来源,有多个可以用','隔开
- policy.SetIsOriginAllowed(x => true) // .WithOrigins(YLShipBuildLandMap.Web.Configuration.Current.CROSDomainList.ToArray())
- .AllowAnyHeader()
- .AllowAnyMethod()
- .AllowCredentials();
- });
- });*/
- services.AddHttpClient();
- }
- // 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();
- }
- else
- {
- app.UseExceptionHandler("/Error");
- }
- app.UseDefaultFiles(new DefaultFilesOptions
- {
- DefaultFileNames = new List<string>
- {
- "default.html"
- }
- });
- var provider = new FileExtensionContentTypeProvider();
- provider.Mappings[".properties"] = "application/octet-stream";
- app.UseStaticFiles(new StaticFileOptions
- {
- ContentTypeProvider = provider
- });
- YLShipBuildLandMapContext.SetServices(app.ApplicationServices);
- app.UseWebSockets();
- app.UseRouting();
- app.UseAuthentication();
- app.UseAuthorization();
- //配置Cors
- //设定特定ip允许跨域 CustomCorsPolicy是在ConfigureServices方法中配置的跨域策略名称
- //app.UseCors("CustomCorsPolicy");
- app.StartSchedulerJobs();
- //app.Use(next=> context => {
- // context.Request.EnableBuffering();
- // return next(context);
- // });
- app.UseEndpoints(endpoints =>
- {
- endpoints.MapControllers();
- //endpoints.MapHub<TokenSender>("/hubs/token");
- });
- }
- }
- }
|