public static IServiceCollection AddConfigDispatch(this IServiceCollection services) { AddConfigDispatchByConfig(services, AlpacaConfigWrapper.GetConfiguration()); AlpacaConfigWrapper.RegisterChangeCallback(obj => { AddConfigDispatchByConfig(services, AlpacaConfigWrapper.GetConfiguration()); }); return(services); }
public static IServiceCollection AddIOC(this IServiceCollection services) { services.AddSingleton(services); services.AddSingleton <IUserService, UserService>(); services.AddDbContext <ADbContext>(options => options.UseSqlServer(AlpacaConfigWrapper.GetConnectionString())); // Auto load all biz type var bizDlls = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Alpaca.Biz.*.dll"); bizDlls.ToList().ForEach(dll => { Assembly .LoadFrom(dll) .GetTypes() .Where(t => t.Name.EndsWith("Biz")) .ToList() .ForEach(bizType => services.AddScoped(bizType)); }); return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddControllers() .AddNewtonsoftJson(options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore ); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Alpaca.Service.Open", Version = "v1" }); // swagger security c.OperationFilter <AddResponseHeadersFilter>(); c.OperationFilter <AppendAuthorizeToSummaryOperationFilter>(); // add token to header c.OperationFilter <SecurityRequirementsOperationFilter>(); c.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme { Description = "JWT授权(数据将在请求头中进行传递)直接在下面框中输入Bearer {token}(注意两者之间是一个空格)", Name = "Authorization", //jwt默认的参数名称 In = ParameterLocation.Header, //jwt默认存放Authorization信息的位置(请求头中) Type = SecuritySchemeType.ApiKey }); }); services.AddCors(option => option.AddPolicy("AllowCors", builder => builder.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod())); // Auth services .AddAuthentication("Bearer") .AddJwtBearer(o => { o.TokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(AlpacaConfigWrapper.GetTokenSecretKey())), ValidateIssuer = true, ValidIssuer = "API", ValidateAudience = true, ValidAudience = "User", ValidateLifetime = true, ClockSkew = TimeSpan.Zero, }; }); services.AddIOC(); services.AddConfigDispatch(); }
public static ADbContext Create(string connectionString) { return(new ADbContext(connectionString ?? AlpacaConfigWrapper.GetConnectionString())); }
public void ReloadConfig() { var dc = AlpacaConfigWrapper.GetModel <DispatchConfig>("ConfigDispatch:Config"); Logger.Debug($"{nameof(RedisDispatchService)}: ReloadConfig.ConnectionString = {dc.ConnectionString}"); }
static TokenMaker() { _secretKey = AlpacaConfigWrapper.GetTokenSecretKey(); }