hwh
2024-07-11 982b21b945c3621e24c3e699e48a95a161bb192a
Wms/Wms/Startup.cs
@@ -14,6 +14,13 @@
using Wms.Tools;
using WMS.Entity.Context;
using WMS.IBLL.IDataServer;
using Serilog;
using Autofac.Core;
using Utility;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using Utility.Job;
namespace Wms
{
@@ -35,9 +42,13 @@
            var url2 = Configuration.GetSection("ApiUrlConfig:AgvHost").Value + Configuration.GetSection("ApiUrlConfig:IssueComApiUrl").Value;
            //调用定时任务
            services.AddHostedService<DailyTaskService>(provider =>
            new DailyTaskService(url,url2));
            new DailyTaskService(url, url2));
            services.AddControllers()
            services.AddControllers(options =>
            {
                options.Filters.Add<RequestAuditLogFilter>();
                options.Filters.Add<CustomerExceptionFilter>();
            })
                .AddJsonOptions(options =>
                    {
                        //不使用驼峰样式的key
@@ -81,7 +92,7 @@
                            .SetIsOriginAllowed(_ => true)
                            .AllowAnyHeader()
                            .AllowCredentials();
                    });
            });
            #endregion
@@ -103,6 +114,12 @@
            services.Configure<ApiUrlConfig>(Configuration.GetSection("ApiUrlConfig"));
            //数据库配置
            BaseDbConfig.ConnectionString = Configuration.GetSection("AppSettings:ConnectionString").Value;
            //验签配置文件
            SignConfig.ERPAppKey = Configuration.GetSection("SignConfig:ERPAppKey").Value;
            SignConfig.MESAppKey = Configuration.GetSection("SignConfig:MESAppKey").Value;
            SignConfig.LIMSAppKey = Configuration.GetSection("SignConfig:LIMSAppKey").Value;
            SignConfig.FuMaAppKey = Configuration.GetSection("SignConfig:FuMaAppKey").Value;
            SignConfig.Minutes = double.Parse(Configuration.GetSection("SignConfig:Minutes").Value);
            #region AutoMapper注入
@@ -110,6 +127,18 @@
            services.AddAutoMapper(typeof(AutoMapperProfile)); // automapper依赖
            #endregion
            //注册serilog
            services.AddConfigSerilog();
            services.AddScoped<ApiResponseActionFilter>();
            services.AddScoped<UnitOfWorkAttribute>();
            services.AddSingleton<ISqlSugarClient>(DataContext.Db); // 单例注册
            services.AddTransient<IUnitOfWork, SqlSugarUnitOfWork>(); // 事务与工作单元注册
            services.AddHostedService<HostedService>();
            services.AddSingleton<SchedulerCenter>();
            services.AddTransient<UserManager>();
            services.AddTransient<IHttpContextAccessor, HttpContextAccessor>();
        }
        public void ConfigureContainer(ContainerBuilder builder)
        {
@@ -133,15 +162,18 @@
                    c.RoutePrefix = string.Empty;
                });
            }
            //全局返回规范
            //app.UseApiResponse();//弃用 改用Filter [ServiceFilter(typeof(ApiResponseActionFilter))]
            //使用Serilog记录请求日志
            app.UseSerilogRequestLogging();
            //app.UseHttpsRedirection();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseCors("MyCors");//跨域
            app.UseEndpoints(endpoints =>
            {