Skip to content

Commit

Permalink
#27 even better for health check :)
Browse files Browse the repository at this point in the history
  • Loading branch information
thangchung committed Dec 7, 2018
1 parent 5b5d695 commit a570f61
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 40 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

A set of cloud-native tools and utilities for .NET Core.

### Features

- Simple libraries. No frameworks. Little abstraction.
- Opt-in and out of the box [features](https://github.com/cloudnative-netcore/netcorekit/wiki/Miniservice-template-guidance) with [Feature Toggles](https://martinfowler.com/articles/feature-toggles.html) technique.
- Generic repository for data persistence.
- Adhere to [twelve-factor app paradigm](https://12factor.net) and more.
- Resilience and health check out of the box.
- Easy for configuration management.
- [Domain-driven Design](https://en.wikipedia.org/wiki/Domain-driven_design) in mind.
- Simply [Clean Architecture](http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html) supports.
- Authentication/Authorization with OAuth 2.0 and OpenID Connect.
- Clean and demystify error, debug logs.
- API versioning from Docker container to WebAPI.
- Documentation template with OpenAPI documentation.
- Work natively with Kubernetes or even with Service Mesh(Istio).

## Less code to get starting

Small, lightweight, cloud-native out of the box, and much more simple to get starting with miniservices approach. [Why miniservices?](https://thenewstack.io/miniservices-a-realistic-alternative-to-microservices)
Expand Down Expand Up @@ -70,22 +86,6 @@ public class Startup

</details>

### Features

- Simple libraries. No frameworks. Little abstraction.
- Modular (Easy to swap out Utils, Domain, AspNetCore, Clean Architecture, Open API, Entity Framework Core, Event Bus...)
- Adhere to [twelve-factor app paradigm](https://12factor.net) and more.
- Resilience and health check out of the box.
- Easy for configuration management.
- Simply clean architecture supports.
- Authentication/Authorization with OAuth 2.0 and OpenID Connect.
- Clean and demystify error, debug logs.
- API versioning from Docker container to WebAPI.
- Documentation template with OpenAPI documentation.
- Work natively with Kubernetes or even with Service Mesh.

More information about the number of features can be find at [List of features](https://github.com/cloudnative-netcore/netcorekit/wiki/Miniservice-template-guidance)

### Contributing

1. Fork it!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AspNetCoreHostingModel>inprocess</AspNetCoreHostingModel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BeatPulse" Version="3.0.0" />
<PackageReference Include="BeatPulse.MongoDb" Version="3.0.0" />
<PackageReference Include="BeatPulse.UI" Version="3.0.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Expand Down
16 changes: 2 additions & 14 deletions samples/BiMonetaryApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using BeatPulse.UI;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using NetCoreKit.Infrastructure.AspNetCore.Miniservice;
Expand All @@ -9,23 +8,12 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddMongoMiniService()
.AddBeatPulse()
.AddBeatPulseUI();
services.AddMongoMiniService();
}

public void Configure(IApplicationBuilder app)
{
app
.UseBeatPulse(options =>
{
options.ConfigurePath(path: "healthz") //default hc
.ConfigureTimeout(milliseconds: 1500) // default -1 infinitely
.ConfigureDetailedOutput(detailedOutput: true, includeExceptionMessages: true); //default (true,false)
})
.UseBeatPulseUI()
.UseMiniService();
app.UseMiniService();
}
}
}
5 changes: 3 additions & 2 deletions samples/BiMonetaryApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ApiVersion": { "Enabled": true },
"OpenApi": {
"Enabled": true,
"UI": { "Enabled": true },
"OpenApiUI": { "Enabled": true },
"ApiInfo": {
"Title": "BiMonetary API",
"Description": "An application with Swagger, Swashbuckle, and API versioning.",
Expand All @@ -39,7 +39,8 @@
"example2_api_scope": "Example 2 APIs"
},
"Audience": "api"
}
},
"HealthUI": { "Enabled": true }
},
"BeatPulse-UI": {
"Liveness": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.Reflection;
using BeatPulse.UI;
using IdentityServer4.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics;
Expand Down Expand Up @@ -93,6 +94,15 @@ public static IApplicationBuilder UseMiniService(this IApplicationBuilder app)

app.UseMiddleware<ErrorHandlerMiddleware>();

app
.UseBeatPulse(options =>
{
options.ConfigurePath("healthz") //default hc
.ConfigureTimeout(1500) // default -1 infinitely
.ConfigureDetailedOutput(true, true); //default (true,false)
})
.UseBeatPulseUI();

if (feature.IsEnabled("OpenApi:Profiler"))
app.UseMiddleware<MiniProfilerMiddleware>();

Expand Down Expand Up @@ -132,7 +142,7 @@ public static IApplicationBuilder UseMiniService(this IApplicationBuilder app)
if (feature.IsEnabled("OpenApi"))
app.UseSwagger();

if (feature.IsEnabled("OpenApi:UI"))
if (feature.IsEnabled("OpenApi:OpenApiUI"))
app.UseSwaggerUI(
c =>
{
Expand All @@ -153,13 +163,11 @@ public static IApplicationBuilder UseMiniService(this IApplicationBuilder app)
}
if (feature.IsEnabled("OpenApi:Profiler"))
{
c.IndexStream = () =>
typeof(ServiceCollectionExtensions)
.GetTypeInfo()
.Assembly
.GetManifestResourceStream("NetCoreKit.Infrastructure.AspNetCore.Miniservice.Swagger.index.html");
}
});

return app;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Linq;
using BeatPulse.Core;
using BeatPulse.UI;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
Expand All @@ -16,6 +18,7 @@ namespace NetCoreKit.Infrastructure.AspNetCore.Miniservice
public static partial class ServiceCollectionExtensions
{
public static IServiceCollection AddEfCoreMiniService<TDbContext>(this IServiceCollection services,
Action<BeatPulseContext> beatPulseCtx = null,
Action<IServiceCollection> preDbWorkHook = null,
Action<IServiceCollection, IServiceProvider> postDbWorkHook = null)
where TDbContext : DbContext
Expand Down Expand Up @@ -77,6 +80,11 @@ public static partial class ServiceCollectionExtensions

if (feature.IsEnabled("OpenApi:Profiler"))
services.AddApiProfilerCore();

services.AddBeatPulse(beatPulseCtx);

if (feature.IsEnabled("HealthUI"))
services.AddBeatPulseUI();
}

return services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using BeatPulse.Core;
using BeatPulse.UI;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -13,6 +15,7 @@ namespace NetCoreKit.Infrastructure.AspNetCore.Miniservice
public static partial class ServiceCollectionExtensions
{
public static IServiceCollection AddMongoMiniService(this IServiceCollection services,
Action<BeatPulseContext> beatPulseCtx = null,
Action<IServiceCollection> preDbWorkHook = null,
Action<IServiceCollection, IServiceProvider> postDbWorkHook = null)
{
Expand Down Expand Up @@ -64,6 +67,11 @@ public static partial class ServiceCollectionExtensions

if (feature.IsEnabled("OpenApi:Profiler"))
services.AddApiProfilerCore();

services.AddBeatPulse(beatPulseCtx);

if (feature.IsEnabled("HealthUI"))
services.AddBeatPulseUI();
}

return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
<PackageReference Include="MediatR" Version="5.1.0" />
<PackageReference Include="Scrutor" Version="3.0.1" />
<PackageReference Include="System.Reactive" Version="4.1.0" />
<PackageReference Include="BeatPulse" Version="3.0.0" />
<PackageReference Include="BeatPulse.UI" Version="3.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using BeatPulse.Core;
using BeatPulse.UI;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -12,7 +14,8 @@ namespace NetCoreKit.Infrastructure.AspNetCore.Miniservice
public static partial class ServiceCollectionExtensions
{
public static IServiceCollection AddMiniService(this IServiceCollection services,
Action<IServiceCollection, IServiceProvider> preHook = null)
Action<IServiceCollection, IServiceProvider> preHook = null,
Action<BeatPulseContext> beatPulseCtx = null)
{
services.AddFeatureToggle();

Expand Down Expand Up @@ -53,6 +56,11 @@ public static partial class ServiceCollectionExtensions

if (feature.IsEnabled("OpenApi:Profiler"))
services.AddApiProfilerCore();

services.AddBeatPulse(beatPulseCtx);

if (feature.IsEnabled("HealthUI"))
services.AddBeatPulseUI();
}

return services;
Expand Down

0 comments on commit a570f61

Please sign in to comment.