1. Specified RuntimeFrameworkVersion to 2.1.3 2. Specified Microsoft.AspNetCore.App meta package version to 2.1.3 3. Updated NuGetPackages to support ASP.NET Core 2.1.3 i. Microsoft.AspNetCore.Hosting 2.1.0->2.1.1 ii. Microsoft.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Design, Microsoft.EntityFrameworkCore.Relational, Microsoft.EntityFrameworkCore.SqlServer 2.1.0->2.1.2 iii.Microsoft.Extensions.Logging 2.1.0->2.1.1 iv. Microsoft.ApplicationInsights.AspNetCore 2.2.1->2.4.1 v. Microsoft.ApplicationInsights.DependencyCollector 2.6.1-> 2.7.2 vi. Microsoft.ApplicationInsights.ServiceFabric 2.1.1-beta1->2.1.1 vii. Microsoft.Extensions.Logging.AzureAppServices 2.1.0-> 2.1.1 viii. Microsoft.AspNetCore.App 2.1.0->2.1.3 ix. Microsoft.VisualStudio.Azure.Fabric.MSBuild 1.6.5->1.6.7 x. Microsoft.AspNetCore.SignalR, Microsoft.AspNetCore.SignalR.Core, Microsoft.AspNetCore.SignalR.Redis 1.0.0->1.0.3 4. Updated NuGetPackages i. System.Threading.Tasks.Extensions 4.5.0->4.5.1 ii. WindowsAzure.Storage 9.1.0->9.3.1 b. DockerFile 1. Updated SDK version to 2.1.401 2. Updated Runtime version to 2.1.3 c. Startup.cs file 1. SetCompatibilityVersion to 2.1 in MVC pipeline (Line 83) 2. Suppress compiler warning 3. Re-factored coding styles d. appsettings.json 1. Updated IdentityUrl to use HTTPS endpoint e. launchsettings.json 1. Used 64bit IIS Express bitness
112 lines
3.7 KiB
C#
112 lines
3.7 KiB
C#
using Microsoft.ApplicationInsights.Extensibility;
|
|
using Microsoft.ApplicationInsights.ServiceFabric;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using WebStatus.Extensions;
|
|
|
|
using TimeSpan = System.TimeSpan;
|
|
|
|
namespace WebStatus
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
RegisterAppInsights(services);
|
|
|
|
services.AddOptions();
|
|
|
|
// Add framework services.
|
|
services.AddHealthChecks(checks =>
|
|
{
|
|
var minutes = 1;
|
|
if (int.TryParse(Configuration["HealthCheck:Timeout"], out int minutesParsed))
|
|
{
|
|
minutes = minutesParsed;
|
|
}
|
|
|
|
checks.AddUrlCheckIfNotNull(Configuration["OrderingUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["OrderingBackgroundTasksUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["BasketUrl"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
|
|
checks.AddUrlCheckIfNotNull(Configuration["CatalogUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["LocationsUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["MarketingUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["PaymentUrl"], TimeSpan.FromMinutes(minutes));
|
|
checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
|
|
checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.Zero); //No cache for this HealthCheck, better just for demos
|
|
});
|
|
|
|
services
|
|
.AddMvc()
|
|
.SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1)
|
|
;
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
{
|
|
loggerFactory.AddAzureWebAppDiagnostics();
|
|
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Home/Error");
|
|
}
|
|
|
|
var pathBase = Configuration["PATH_BASE"];
|
|
if (!string.IsNullOrEmpty(pathBase))
|
|
{
|
|
app.UsePathBase(pathBase);
|
|
}
|
|
|
|
|
|
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
|
|
app.Map("/liveness", lapp => lapp.Run(async ctx => ctx.Response.StatusCode = 200));
|
|
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
|
|
|
|
app.UseStaticFiles();
|
|
|
|
app.UseMvc(routes =>
|
|
{
|
|
routes.MapRoute(
|
|
name: "default",
|
|
template: "{controller=Home}/{action=Index}/{id?}");
|
|
});
|
|
}
|
|
|
|
private void RegisterAppInsights(IServiceCollection services)
|
|
{
|
|
services.AddApplicationInsightsTelemetry(Configuration);
|
|
var orchestratorType = Configuration.GetValue<string>("OrchestratorType");
|
|
|
|
if (orchestratorType?.ToUpper() == "K8S")
|
|
{
|
|
// Enable K8s telemetry initializer
|
|
services.EnableKubernetes();
|
|
}
|
|
if (orchestratorType?.ToUpper() == "SF")
|
|
{
|
|
// Enable SF telemetry initializer
|
|
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
|
|
new FabricTelemetryInitializer());
|
|
}
|
|
}
|
|
}
|
|
}
|