// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(options => { options.SuppressAsyncSuffixInActionNames = false; options.InputFormatters.Insert(0, GetJsonPatchInputFormatter()); }) .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; }); services.AddSwaggerGen(c => { // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } }); services.AddStackExchangeRedisCache(options => { options.Configuration = Configuration["redis:connectionString"]; }); services.AddHttpClient <JobsApiService>(config => { config.BaseAddress = new Uri(Configuration["services:jobsService:url"]); config.Timeout = Utils.ParseTimeSpanExpression(Configuration["services:jobsService:timeout"], TimeSpan.FromMinutes(2)); }).AddTransientHttpErrorPolicy(builder => builder.RetryAsync(Convert.ToInt32(Configuration["services:jobsService:retries"]))); var mongoConnectionString = Configuration["mongo:connectionString"]; var mongoDatabase = Configuration["mongo:database"]; var wrapperDao = new MongoDataAccessObject(new MongoUrl(mongoConnectionString), mongoDatabase); services.AddTransient <IDataAccessObject>(sp => new DistributedCachedDataAccessObject(sp.GetService <IDistributedCache>() !, wrapperDao)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddSwaggerGen(c => { // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } }); services.AddStackExchangeRedisCache(options => { options.Configuration = Configuration["redis:connectionString"]; }); var clusterImplementations = DiscoverClusterImplementations(); services.AddSingleton(clusterImplementations); var mongoConnectionString = Configuration["mongo:connectionString"]; var mongoDatabase = Configuration["mongo:database"]; var wrapperDao = new MongoDataAccessObject(new MongoUrl(mongoConnectionString), mongoDatabase); services.AddTransient <IDataAccessObject>(sp => new DistributedCachedDataAccessObject(sp.GetService <IDistributedCache>() !, wrapperDao)); services.AddControllers(options => { options.SuppressAsyncSuffixInActionNames = false; options.InputFormatters.Insert(0, GetJsonPatchInputFormatter()); }) .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(options => { options.SuppressAsyncSuffixInActionNames = false; options.InputFormatters.Insert(0, GetJsonPatchInputFormatter()); }) .AddNewtonsoftJson(options => { options.SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }; }); services.AddStackExchangeRedisCache(options => { options.Configuration = Configuration["redis:connectionString"]; }); services.AddSwaggerGen(c => { // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); if (File.Exists(xmlPath)) { c.IncludeXmlComments(xmlPath); } }); var pluginsDirectory = Path.Combine(AppContext.BaseDirectory, "plugins"); var loaders = new List <PluginLoader>(); var mongoConnectionString = Configuration["mongo:connectionString"]; var mongoDatabase = Configuration["mongo:database"]; var wrapperDao = new MongoDataAccessObject(new MongoUrl(mongoConnectionString), mongoDatabase); services.AddTransient <IDataAccessObject>(sp => new DistributedCachedDataAccessObject(sp.GetService <IDistributedCache>() !, wrapperDao)); services.AddHttpClient <ClusterApiService>(config => { config.BaseAddress = new Uri(Configuration["services:clusterService:url"]); config.Timeout = Utils.ParseTimeSpanExpression(Configuration["services:clusterService:timeout"], TimeSpan.FromMinutes(2)); }).AddTransientHttpErrorPolicy(builder => builder.RetryAsync(Convert.ToInt32(Configuration["services:clusterService:retries"]))); services.AddHttpClient <CommonApiService>(config => { config.BaseAddress = new Uri(Configuration["services:commonService:url"]); config.Timeout = Utils.ParseTimeSpanExpression(Configuration["services:commonService:timeout"], TimeSpan.FromSeconds(2)); }).AddTransientHttpErrorPolicy(builder => builder.RetryAsync(Convert.ToInt32(Configuration["services:commonService:retries"]))); services.AddHttpClient <ProjectApiService>(config => { config.BaseAddress = new Uri(Configuration["services:projectService:url"]); config.Timeout = Utils.ParseTimeSpanExpression(Configuration["services:projectService:timeout"], TimeSpan.FromSeconds(2)); }).AddTransientHttpErrorPolicy(builder => builder.RetryAsync(Convert.ToInt32(Configuration["services:projectService:retries"]))); // Initializes the job scheduler var quartzSchedulerSettings = new NameValueCollection { { "quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" }, { "quartz.jobStore.driverDelegateType", Configuration["quartz:driverDelegateType"] }, { "quartz.jobStore.dataSource", "myDS" }, { "quartz.dataSource.myDS.connectionString", Configuration["quartz:dataSource:connectionString"] }, { "quartz.dataSource.myDS.provider", Configuration["quartz:dataSource:provider"] }, { "quartz.jobStore.useProperties", "false" }, { "quartz.serializer.type", "json" }, { "quartz.scheduler.instanceId", "AUTO" }, { "quartz.jobStore.clustered", "true" } }; var schedulerFactory = new StdSchedulerFactory(quartzSchedulerSettings); var scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult(); services.AddSingleton <IJobFactory, JobFactory>(); services.AddSingleton(scheduler); services.AddSingleton <JobSubmitExecutor>(); services.AddSingleton <JobUpdateExecutor>(); services.AddHostedService <JobSchedulingHostedService>(); }