|
| 1 | +<!-- [](https://ci.appveyor.com/project/ThiagoBarradas/aspnet-scaffolding/branch/master) |
| 2 | +[](https://www.codacy.com/app/ThiagoBarradas/aspnet-scaffolding?utm_source=github.com&utm_medium=referral&utm_content=ThiagoBarradas/aspnet-scaffolding&utm_campaign=Badge_Grade) --> |
| 3 | +[](https://www.nuget.org/packages/AspNetScaffolding3/) |
| 4 | +[](https://www.nuget.org/packages/AspNetScaffolding3/) |
| 5 | + |
| 6 | +# AspNetScaffolding3 |
| 7 | + |
| 8 | +Build web api fast and easily with aspnet core > 3.1 |
| 9 | + |
| 10 | +## Install via NuGet |
| 11 | + |
| 12 | +``` |
| 13 | +PM> Install-Package AspNetScaffolding3 |
| 14 | +``` |
| 15 | + |
| 16 | +# Create An Application |
| 17 | + |
| 18 | +Basic steps: |
| 19 | + |
| 20 | +- Creates a new empty web api project with aspnet core 3.1; |
| 21 | +- Edit your `Program.cs` like example; |
| 22 | +- Edit your `Startup.cs` like example; |
| 23 | +- Create your `appsettings.json` and per environment, like `appsettings.Staging.json` (Environment is obtained by `ASPNETCORE_ENVIRONMENT`) |
| 24 | +- Create your controllers inherit from `BaseController` from AspNetScaffolding; |
| 25 | +- FluentValidation is automatic configured, just implements validator and use `this.Validate(obj);` in your action; |
| 26 | +- This project uses `WebApi.Models` and can handler `ApiResponse` and `ApiException` like `NotFoundException`, `BadRequestException`, `UnauthorizedException`, etc; |
| 27 | +- This project includes restsharp autolog for serilog with current RequestKey; |
| 28 | +- To use AutoMapper you only need to create your mapping inheriting from Profile; |
| 29 | + |
| 30 | +```c# |
| 31 | +// Program.cs |
| 32 | + |
| 33 | +public class Program |
| 34 | +{ |
| 35 | + public static void Main(string[] args) |
| 36 | + { |
| 37 | + var config = new ApiBasicConfiguration |
| 38 | + { |
| 39 | + ApiName = "My AspNet Scaffolding", |
| 40 | + ApiPort = 8700, |
| 41 | + EnvironmentVariablesPrefix = "Prefix_", |
| 42 | + ConfigureHealthcheck = Startup.ConfigureHealthcheck, |
| 43 | + ConfigureServices = Startup.ConfigureServices, |
| 44 | + Configure = Startup.Configure, |
| 45 | + AutoRegisterAssemblies = new Assembly[] |
| 46 | + { Assembly.GetExecutingAssembly() } |
| 47 | + }; |
| 48 | + |
| 49 | + Api.Run(config); |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +```c# |
| 55 | +// Startup.cs |
| 56 | + |
| 57 | +public static class Startup |
| 58 | +{ |
| 59 | + public static void ConfigureHealthcheck(IHealthChecksBuilder builder, IServiceProvider provider) |
| 60 | + { |
| 61 | + // add health check configuration |
| 62 | + builder.AddMongoDb("mongodb://localhost:27017"); |
| 63 | + } |
| 64 | + |
| 65 | + public static void ConfigureServices(IServiceCollection services) |
| 66 | + { |
| 67 | + // add services |
| 68 | + services.AddSingleton<ISomething, Something>(); |
| 69 | + } |
| 70 | + |
| 71 | + public static void Configure(IApplicationBuilder app) |
| 72 | + { |
| 73 | + // customize your app |
| 74 | + app.UseAuthentication(); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +``` |
| 79 | + |
| 80 | +App Settings |
| 81 | +```json |
| 82 | +// appsettings.{environment}.json or appsettings.json |
| 83 | + |
| 84 | +{ |
| 85 | + "ApiSettings": { |
| 86 | + "AppUrl": "http://localhost:8700", |
| 87 | + "JsonSerializer": "Snakecase", |
| 88 | + "PathPrefix": "myapp/{version}", |
| 89 | + "UseStaticFiles": true, |
| 90 | + "StaticFilesPath": "assets", |
| 91 | + "Domain": "MyDomain", |
| 92 | + "Application": "MyApp", |
| 93 | + "Version": "v1", |
| 94 | + "BuildVersion": "1.0.0", |
| 95 | + "UseOriginalEnumValue": false, |
| 96 | + "SupportedCultures": [ "pt-BR", "es-ES", "en-US" ], |
| 97 | + "RequestKeyProperty": "RequestKey", |
| 98 | + "AccountIdProperty": "AccountId", |
| 99 | + "TimezoneHeader": "Timezone", |
| 100 | + "TimezoneDefault": "America/Sao_Paulo", |
| 101 | + "TimeElapsedProperty": "X-Internal-Time", |
| 102 | + "JsonFieldSelectorProperty": "fields" |
| 103 | + }, |
| 104 | + "HealthcheckSettings": { |
| 105 | + "Enabled": true, |
| 106 | + "Path": "healthcheck", |
| 107 | + "LogEnabled": false |
| 108 | + }, |
| 109 | + "ShutdownSettings": { |
| 110 | + "ShutdownTimeoutIsSeconds" : 30, |
| 111 | + "Enabled" : true, |
| 112 | + "Redirect" : false |
| 113 | + }, |
| 114 | + "DbSettings": { |
| 115 | + "ConnectionString": "mongodb://user:pass@localhost:27017/DatabaseName", |
| 116 | + "Name": "DatabaseName" |
| 117 | + }, |
| 118 | + "CacheSettings": { |
| 119 | + "Enabled": true, |
| 120 | + "UseRedis": true, |
| 121 | + "UseLocker": true, |
| 122 | + "TimeoutInMs": 1000, |
| 123 | + "Ssl": false, |
| 124 | + "Password": "RedisAuth", |
| 125 | + "Host": "localhost", |
| 126 | + "Port": 6379, |
| 127 | + "LockerPrefix": "app-locker-", |
| 128 | + "LockerTtlInSeconds": 100, |
| 129 | + "LockerDb": 0, |
| 130 | + "CachePrefix": "app-cache-", |
| 131 | + "CacheTtlInSeconds": 900, |
| 132 | + "CacheDb": 0 |
| 133 | + }, |
| 134 | + "QueueSettings": { |
| 135 | + "Enabled": false, |
| 136 | + "RetryTTL": 20000, |
| 137 | + "RetryTTLFactor": 2.0, |
| 138 | + "RetryCount": 5, |
| 139 | + "QueueConnectionString": "amqp://guest:guest@localhost:5672/VHost", |
| 140 | + "VHostApi": "http://guest:guest@localhost:15672/api/queues/VHost", |
| 141 | + "QueueName": "my-queue", |
| 142 | + "ExchangeToSubscribe": "main.topic", |
| 143 | + "EventsToSubscribe": "event.something.created,event.other.#", |
| 144 | + "MaxThreads": 200, |
| 145 | + "AutoAckOnSuccess": true |
| 146 | + }, |
| 147 | + "IpRateLimiting": { |
| 148 | + "Enabled" : true, |
| 149 | + "EnableEndpointRateLimiting": false, |
| 150 | + "StackBlockedRequests": false, |
| 151 | + "RealIpHeader": "X-Real-IP", |
| 152 | + "ClientIdHeader": "X-ClientId", |
| 153 | + "HttpStatusCode": 429, |
| 154 | + "IpWhitelist": [], |
| 155 | + "EndpointWhitelist": [], |
| 156 | + "ClientWhitelist": [], |
| 157 | + "GeneralRules": [ |
| 158 | + { |
| 159 | + "Endpoint": "*", |
| 160 | + "Period": "1m", |
| 161 | + "Limit": 5 |
| 162 | + }, |
| 163 | + { |
| 164 | + "Endpoint": "*", |
| 165 | + "Period": "1h", |
| 166 | + "Limit": 1000 |
| 167 | + } |
| 168 | + ], |
| 169 | + "QuotaExceededResponse": { |
| 170 | + "Content": "{{ \"message\": \"Quota exceeded. Maximum allowed: {0} per {1}. Please try again in {2} second(s).\" }}", |
| 171 | + "ContentType": "application/json", |
| 172 | + "StatusCode": 429 |
| 173 | + } |
| 174 | + }, |
| 175 | + "LogSettings": { |
| 176 | + "IgnoredRoutes": [], |
| 177 | + "DebugEnabled": true, |
| 178 | + "TitlePrefix": "[{Application}] ", |
| 179 | + "JsonBlacklistRequest": [ "*password", "*card.number", "*creditcardnumber", "*cvv" ], |
| 180 | + "JsonBlacklistResponse": [ "*password", "*card.number", "*creditcardnumber", "*cvv" ], |
| 181 | + "SeqOptions": { |
| 182 | + "Enabled": true, |
| 183 | + "MinimumLevel": "Verbose", |
| 184 | + "Url": "http://localhost:5341", |
| 185 | + "ApiKey": "XXXX" |
| 186 | + }, |
| 187 | + "NewRelicOptions": { |
| 188 | + "Enabled": false, |
| 189 | + "AppName": "Verbose", |
| 190 | + "LicenseKey": "XXXX" |
| 191 | + }, |
| 192 | + "SplunkOptions": { |
| 193 | + "Enabled": false, |
| 194 | + "MinimumLevel": "Verbose", |
| 195 | + "Url": "http://localhost:8088/services/collector", |
| 196 | + "Token": "XXXX", |
| 197 | + "Index": "my.index", |
| 198 | + "Application": "MyApp :Ds", |
| 199 | + "ProcessName": "Domain.App", |
| 200 | + "Company": "MyCompany", |
| 201 | + "ProductVersion": "1.0.0", |
| 202 | + "SourceType": "_json" |
| 203 | + }, |
| 204 | + "DataDogOptions": { |
| 205 | + "Enabled": false, |
| 206 | + "MinimumLevel": "Verbose", |
| 207 | + "ApiKey": "XXX", |
| 208 | + "Service": null, |
| 209 | + "Source": null, |
| 210 | + "Host": null, |
| 211 | + "Tags": [] |
| 212 | + } |
| 213 | + }, |
| 214 | + "DocsSettings": { |
| 215 | + "Enabled": true, |
| 216 | + "Title": "MyApp API Reference", |
| 217 | + "AuthorName": "Thiago Barradas", |
| 218 | + "AuthorEmail": " [email protected]", |
| 219 | + "PathToReadme": "DOCS.md", |
| 220 | + "IgnoredEnums": [ "none", "undefined" ] |
| 221 | + } |
| 222 | +} |
| 223 | + |
| 224 | +``` |
| 225 | + |
| 226 | +## How can I contribute? |
| 227 | + |
| 228 | +Please, refer to [CONTRIBUTING](.github/CONTRIBUTING.md) |
| 229 | + |
| 230 | +## Found something strange or need a new feature? |
| 231 | + |
| 232 | +Open a new Issue following our issue template [ISSUE_TEMPLATE](.github/ISSUE_TEMPLATE.md) |
| 233 | + |
| 234 | +## Changelog |
| 235 | + |
| 236 | +See in [nuget version history](https://www.nuget.org/packages/AspNetScaffolding3) |
| 237 | + |
| 238 | +## Did you like it? Please, make a donate :) |
| 239 | + |
| 240 | +if you liked this project, please make a contribution and help to keep this and other initiatives, send me some Satochis. |
| 241 | + |
| 242 | +BTC Wallet: `1G535x1rYdMo9CNdTGK3eG6XJddBHdaqfX` |
| 243 | + |
| 244 | + |
0 commit comments