// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Version = "v1", Title = "Maternity Benefit Simulation API", Description = "...", TermsOfService = new Uri("https://example.com/terms") }); // Set the comments path for the Swagger JSON and UI. var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); c.IncludeXmlComments(xmlPath); }); services.AddMemoryCache(); InjectMaternityBenefits(services); services.AddScoped <IJoinResults, Joiner>(); services.AddScoped <IRestClient, RestSharp.RestClient>(); // Rules options var rulesUrl = Configuration["RulesOptions:Url"] ?? Environment.GetEnvironmentVariable("RULES_URL"); var rulesOptions = new RulesOptions() { Url = rulesUrl }; services.AddSingleton <IOptions <RulesOptions> >(x => Options.Create(rulesOptions)); // Password Filter options var passwordFilter = Configuration["PasswordOptions:Password"] ?? Environment.GetEnvironmentVariable("PASSWORD_FILTER"); var passwordOptions = new PasswordFilterOptions() { Password = passwordFilter }; services.AddSingleton <IOptions <PasswordFilterOptions> >(x => Options.Create(passwordOptions)); services.AddScoped <PasswordFilterAttribute>(); // DB injection: Only needed if using a DB implementation for storage if (USING_DB) { string connectionString = Configuration.GetConnectionString("DefaultDB") ?? Environment.GetEnvironmentVariable("DEFAULT_DB"); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(connectionString, b => b.MigrationsAssembly("esdc-simulation-api"))); } }
/// <summary> /// Gets a rule table with the specified configuration optiosn. /// </summary> /// <param name="options">Configuration options for the resulting rule table.</param> /// <returns>Rule table with the specified configuration options.</returns> public static RuleTableBase <object, Json.Expression, ExpressionJsonSerializationContext> Get(RulesOptions options) { var res = default(RuleTableBase <object, Json.Expression, ExpressionJsonSerializationContext>); lock (s_tables) { var tableRef = default(WeakReference <RuleTableBase <object, Json.Expression, ExpressionJsonSerializationContext> >); if (!s_tables.TryGetValue(options, out tableRef)) { res = CreateRuleTable(options); tableRef = new WeakReference <RuleTableBase <object, Json.Expression, ExpressionJsonSerializationContext> >(res); s_tables[options] = tableRef; } else { if (!tableRef.TryGetTarget(out res)) { res = CreateRuleTable(options); tableRef.SetTarget(res); } } } return(res); }