A modular microservice framework for ASP.NET Core
- Run
.UseNethium()
on yourIWebHostBuilder
for 2.x
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseNethium(args, CreateLoggerFactory())
.UseStartup<Startup>();
for 3.0
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder
.UseNethium()
.UseStartup<Startup>();
});
- Register microservice interfaces in
ConfigureServices
services.RegisterInterface<IStoreService>("store");
services.RegisterInterface<IAggregateService>("aggregate");
- Register microservice class in
ConfigureServices
services.RegisterService<IStoreService, StoreController>("/api/store", "/api/store/health");
- Register microservice stub assembly in
ConfigureServices
services.AddStub(Assembly.GetAssembly(typeof(SwaggerException)));
- Run
.AddNethiumControllers()
on yourIMvcBuilder
services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddNethiumControllers();
- Run
.AddNethiumServices()
on your IServiceCollection
services.AddNethiumServices();
- Enable swagger and authorization if needed in
Configure
app.UseAuthentication();
app.UseMvc();
app.UseSwagger();
app.UseSwaggerUi3();
You can bootstrap Nethium configuration in three ways:
- Write your configuration in nethium.json
- Configure them in
.UseNethium()
- Use environment variables
The config entries are:
Config Entry | Description |
---|---|
Nethium:Consul:Address | Address of Consul Agent |
Nethium:Consul:Datacenter | Datacenter of Consul |
Nethium:Consul:Token | Token of Consul |
Nethium:Consul:WaitTime | Wait time of Consul |
Nethium:Consul:Prefix | Key prefix |
Nethium:Consul:ConfigurationPrefix | Key prefix to be removed |
Nethium:Consul:Watch | Key to watch for refreshing configuration |
After framework bootstrap, you can also store your configuration in Consul Key/Value
Config Entry | Description |
---|---|
Nethium:ServerId | Server ID |
Nethium:ServerSecretKey | Server JWT signing key |
Nethium:BaseUrl | Server base url |
Nethium:Port | Server port |
You can run the example docker-compose project in test/demo/DockerCompose by docker-compose up --build
.
This command should build three ASP.NET Core image hosting five microservice, and bootstrap the cluster with three consul server and three consul client.
You may need to add a settings/version
key to the Consul Key/Value storage so the apps will startup.