Skip to content

A Nuget Package for Bootstrapping a .NET Microservice Application with utilities like Logging/Tracing, Cors, Configuration, etc. ๐Ÿš€

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE.md
Notifications You must be signed in to change notification settings

mrkresnofatih/SuperBootstrapBase

Repository files navigation

DesertCamel.BaseMicroservices.SuperBootstrap.Base

A Nuget Package for Bootstrapping a .NET Microservice Application with utilities like Logging/Tracing, Cors, Configuration, etc.

Getting Started

In the Program.cs file, write:

using DesertCamel.BaseMicroservices.SuperIdentity;

var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();  // important

var startup = new Startup(builder.Configuration);
startup.ConfigureServices(builder.Services);

var app = builder.Build();
startup.Configure(app, builder.Environment);

app.Run();

Your Startup.cs file should be implemented as follows:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        // other services
        services.AddControllers();
        services.AddEndpointsApiExplorer();
        services.AddSwaggerGen();

        services.AddBootstrapBase(Configuration);
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseSwagger();
            app.UseSwaggerUI();
        }

        // initial db migration/setup if any

        app.UseRouting();
        app.UseCors();  // remember to always implement this
        app.UseAuthorization();

        app.UseBootstrapBase(); // set this exactly before app.UseEndpoints
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }
}

Add to your appsettings.json these in the root level json tree:

{
    "Serilog": {
        "Using": [ "Serilog.Sinks.Console" ],
        "MinimumLevel": {
        "Default": "Information",
        "Override": {
            "Microsoft.EntityFrameworkCore.Database.Command": "Warning"
        }
        },
        "WriteTo": [
            {
                "Name": "Console",
                "Args": {
                "outputTemplate": "{Timestamp:o} [{Level:u4}] [{CorrelationId}] [{SourceContext}] {Message}{NewLine}{Exception}"
                }
            }
        ],
        "Enrich": [ "FromLogContext" ],
        "Destructure": []
  },
  "SuperBootstrap": {
        "Cors": {
            "AllowedOrigins": [
                "http://localhost:5068",
                "http://localhost:3000"
            ]
        }
  }
}

About

A Nuget Package for Bootstrapping a .NET Microservice Application with utilities like Logging/Tracing, Cors, Configuration, etc. ๐Ÿš€

Topics

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENSE
Apache-2.0
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages