Skip to content
This repository has been archived by the owner on Jul 10, 2020. It is now read-only.

AspNet Core Scaffolding with log, serializer, all structure to work good for me :D

License

Notifications You must be signed in to change notification settings

ThiagoBarradas/aspnet-scaffolding

Repository files navigation

⚠️ DEPRECATED ⚠️

This version is no longer supported and it do not will receive new

Please, update your project to new version of scaffolding. It is compatible, you just need update framework to netcoreapp3.1, remove AspNetScaffolding and install AspNetScaffolding3.

https://github.com/ThiagoBarradas/aspnet-scaffolding3



Build status Codacy Badge NuGet Downloads NuGet Version

AspNetScaffolding

Build web api fast and easily with aspnet core 2.2

Install via NuGet

PM> Install-Package AspNetScaffolding

Create An Application

Basic steps:

  • Creates a new empty web api project with aspnet core 2.2;
  • Edit your Program.cs like example;
  • Edit your Startup.cs like example;
  • Create your appsettings.json and per environment, like appsettings.Staging.json (Environment is obtained by ASPNETCORE_ENVIRONMENT)
  • Create your controllers inherit from BaseController from AspNetScaffolding;
  • FluentValidation is automatic configured, just implements validator and use this.Validate(obj); in your action;
  • This project uses WebApi.Models and can handler ApiResponse and ApiException like NotFoundException, BadRequestException, UnauthorizedException, etc;
  • This project includes restsharp autolog for serilog with current RequestKey;
// Program.cs

public class Program
{
    public static void Main(string[] args)
    {
        var config = new ApiBasicConfiguration
        {
            ApiName = "My AspNet Scaffolding",
            ApiPort = 8700,
            EnvironmentVariablesPrefix = "Prefix_",
            ConfigureHealthcheck = Startup.AdditionalConfigureHealthcheck,
            ConfigureServices = Startup.AdditionalConfigureServices,
            Configure = Startup.AdditionalConfigure,
            AutoRegisterAssemblies = new Assembly[] 
				{ Assembly.GetExecutingAssembly() }
        };

        Api.Run(config);
    }
}
// Startup.cs

public static class Startup
{
    public static void AdditionalConfigureHealthcheck(IHealthChecksBuilder builder, IServiceProvider services)
    {
        // add health check configuration
        builder.AddMongoDb("mongodb://localhost:27017");
    }

    public static void AdditionalConfigureServices(IServiceCollection services)
    {
        // add services
        services.AddSingleton<ISomething, Something>();
    }

    public static void AdditionalConfigure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // customize your app
        app.UseAuthentication();
    }
}

App Settings

// appsettings.{environment}.json or appsettings.json

{
  "ApiSettings": {
    "AppUrl": "http://localhost:5855",
    "JsonSerializer": "Snakecase",
    "PathPrefix": "myapp/{version}",
    "Domain": "MyDomain",
    "Application": "MyApp",
    "Version": "v1",
    "BuildVersion": "1.0.0",
    "SupportedCultures": [ "pt-BR", "es-ES", "en-US" ],
    "RequestKeyProperty": "RequestKey",
    "AccountIdProperty": "AccountId",
    "TimezoneHeader": "Timezone",
    "TimezoneDefault": "America/Sao_Paulo",
    "TimeElapsedProperty": "X-Internal-Time"
  },
  "HealthcheckSettings": {
    "Enabled" :  true,
    "Path": "healthcheck/some-token-if-needed",
	"LogEnabled" : false
  },
  "LogSettings": {
    "DebugEnabled": false,
    "TitlePrefix": "[{Application}] ",
    "JsonBlacklist": [ "*password", "*card.number", "*creditcardnumber", "*cvv" ],
    "SeqOptions": {
      "Enabled": true,
      "MinimumLevel": "Verbose",
      "Url": "http://localhost:5341",
      "ApiKey": "XXXX"
    },
    "SplunkOptions": {
      "Enabled": false,
      "MinimumLevel": "Verbose",
      "Url": "http://localhost:8088/services/collector",
      "Token": "XXXX",
      "Index": "my.index",
      "Application": "MyApp",
      "ProcessName": "Domain.App",
      "Company": "MyCompany",
      "ProductVersion": "1.0.0",
      "SourceType": "_json"
    }
  },
  "DocsSettings": {
    "Enabled": true,
    "Title": "MyApp API Reference",
    "AuthorName": "Thiago Barradas",
    "AuthorEmail": "th.barradas@gmail.com",
    "PathToReadme": "DOCS.md"
  }
}

How can I contribute?

Please, refer to CONTRIBUTING

Found something strange or need a new feature?

Open a new Issue following our issue template ISSUE_TEMPLATE

Changelog

See in nuget version history

Did you like it? Please, make a donate :)

if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.

BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX

1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX