This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddSingleton<CDriveHasMoreThan1GbFreeHealthCheck>(); | |
services.AddHealthChecks(checks => | |
{ | |
checks.AddCheck<CDriveHasMoreThan1GbFreeHealthCheck>("C Drive has more than 1 GB Free"); | |
}); | |
services.AddMvc(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CDriveHasMoreThan1GbFreeHealthCheck : IHealthCheck | |
{ | |
public ValueTask<IHealthCheckResult> CheckAsync(CancellationToken cancellationToken = default(CancellationToken)) | |
{ | |
long freeSpaceinGb = GetTotalFreeSpaceInGb(@"C:\"); | |
CheckStatus status = freeSpaceinGb > 1 ? CheckStatus.Healthy : CheckStatus.Unhealthy; | |
return new ValueTask<IHealthCheckResult>(HealthCheckResult.FromStatus(status, $"Free Space in GB: {freeSpaceinGb}")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Route("api/[controller]")] | |
public class HealthCheckController : Controller | |
{ | |
private readonly IHealthCheckService _healthCheckService; | |
public HealthCheckController(IHealthCheckService healthCheckService) | |
{ | |
_healthCheckService = healthCheckService; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<environment names="Development"> | |
<h1>This only renders in the Development Environment!</h1> | |
</environment> | |
<environment names="Staging,Production"> | |
<h1>This only renders in the Staging and Production Environments!</h1> | |
</environment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<environment include="Development, Staging" exclude="Development"> | |
<h1>This will not show in Development or Production, but it will show in Staging.</h1> | |
</environment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<environment include="Development"> | |
<h1>This only renders in the Development Environment</h1> | |
</environment> | |
<environment exclude="Development"> | |
<h1>This renders in anything except the Development Environment (Staging, Production, or any custom environment).</h1> | |
</environment> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
// if we're in Development | |
if (env.IsDevelopment()) | |
{ | |
// Show the Light Blue Screen of Death if there's an unhandled exception (RIP Yellow Screen of Death of ASP.NET 4) | |
app.UseDeveloperExceptionPage(); | |
} | |
else | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FeatureViewLocationRazorViewEngine : RazorViewEngine | |
{ | |
public FeatureViewLocationRazorViewEngine() | |
{ | |
var featureFolderViewLocationFormats = new[] | |
{ | |
"~/Features/{1}/{0}.cshtml", | |
"~/Features/Shared/{0}.cshtml", | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using Microsoft.AspNetCore.Mvc.Razor; | |
using JetBrains.Annotations; // Install JetBrains.Annotations NuGet package | |
[assembly: AspMvcViewLocationFormat("~/Features/{1}/{0}.cshtml")] | |
[assembly: AspMvcViewLocationFormat("~/Features/Shared/{0}.cshtml")] | |
namespace WebApplication6.StartupCustomizations | |
{ | |
public class FeatureLocationExpander : IViewLocationExpander | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0" PrivateAssets="All" /> |