// GET: AttendeeModels public async Task <IActionResult> Index() { var _dbstring = Config.GetConnectionString("AttendeeContext"); ViewData["ConnectSource"] = "appsettings.json"; IConfigurationSection configurationSection = Config.GetSection("ConnectionStrings"); if (configurationSection != null) { if (configurationSection.GetValue <string>("AttendeeContext") != null) { ViewData["ConnectSource"] = "Config Server"; } } var cfe = new CFEnvironmentVariables(); var _connect = cfe.getConnectionStringForDbService("user-provided", "AttendeeContext"); if (!string.IsNullOrEmpty(_connect)) { ViewData["ConnectSource"] = "User Provided Service"; _dbstring = _connect; } ViewData["ConnectionString"] = StringCleaner.GetDisplayString("Password="******";", _dbstring, "*****"); return(View(await _context.AttendeeModel.ToListAsync())); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(sharedOptions => { sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddAzureAd(options => Configuration.Bind("AzureAd", options)) .AddCookie(); services.AddMvc(); // Use the Bound Service for connection string if it is found in a User Provided Service string dbString = Configuration.GetConnectionString("AttendeeContext"); CFEnvironmentVariables _env = new CFEnvironmentVariables(); var _connect = _env.getConnectionStringForDbService("user-provided", "AttendeeContext"); if (!string.IsNullOrEmpty(_connect)) { Console.WriteLine($"Using bound service connection string for data: {_connect}"); dbString = _connect; } else { Console.WriteLine($"Using connection string from appsetings.json"); } services.AddDbContext <AttendeeContext>(options => options.UseSqlServer(dbString)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddOptions(); // Enable Redis function if not offline if (!Environment.IsDevelopment()) { // Use Redis cache on CloudFoundry to DataProtection Keys services.AddRedisConnectionMultiplexer(Configuration); services.AddDataProtection() .PersistKeysToRedis() .SetApplicationName("workshopui"); } // End Redis // Add service client library for calling the Fortune Service services.AddScoped <IFortuneService, FortuneServiceClient>(); // End add service client // Load Fortune Service Options services.Configure <FortuneServiceOptions>(Configuration.GetSection("fortuneService")); // End load Fortune Service // Workshop Configuration services.Configure <ConfigServerData>(Configuration.GetSection("workshopConfig")); services.AddConfiguration(Configuration); // Add for Service Options services.ConfigureCloudFoundryOptions(Configuration); // // Add Credhub Client services.AddCredHubClient(Configuration, logFactory); // // Add Service Discovery services.AddDiscoveryClient(Configuration); // End Service Discovery // Add Session Caching function if (Environment.IsDevelopment()) { services.AddDistributedMemoryCache(); } else { // Use Redis cache on CloudFoundry to store session data services.AddDistributedRedisCache(Configuration); } services.AddSession(); // End Session Cache // Add Single Sign-on functionality services.AddAuthentication((options) => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = CloudFoundryDefaults.AuthenticationScheme; }) .AddCookie((options) => { options.AccessDeniedPath = new PathString("/Workshop/AccessDenied"); }) .AddCloudFoundryOAuth(Configuration); services.AddAuthorization(options => { options.AddPolicy("read.fortunes", policy => policy.RequireClaim("scope", "read.fortunes")); }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // End Add SSO // Add Circuit Breaker function services.AddHystrixCommand <FortuneServiceCommand>("FortuneService", Configuration); services.AddHystrixMetricsStream(Configuration); // End Add CB services.AddSingleton <IHealthContributor, SqlServerHealthContributor>(); // Add Cloud Foundry Management actuator endpoint functions services.AddCloudFoundryActuators(Configuration); // End CF Management services.AddMvc(); // Update the connection strings from appSettings.json or Config Server from any User Provided Service of the same name // User Provided Service will take presidence over other sources CFEnvironmentVariables.UpdateConnectionStrings(Configuration); var dbString = Configuration.GetConnectionString("AttendeeContext"); services.AddDbContext <AttendeeContext>(options => options.UseSqlServer(dbString)); // End connection strings // Add RabbitMQ function services.AddRabbitMQConnection(Configuration); // End RabbitMQ }