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
, removeAspNetScaffolding
and installAspNetScaffolding3
.
Build web api fast and easily with aspnet core 2.2
PM> Install-Package AspNetScaffolding
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, likeappsettings.Staging.json
(Environment is obtained byASPNETCORE_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 handlerApiResponse
andApiException
likeNotFoundException
,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"
}
}
Please, refer to CONTRIBUTING
Open a new Issue following our issue template ISSUE_TEMPLATE
See in nuget version history
if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis.
BTC Wallet: 1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX