BackendAPI (Net Core 5) project template with Custom Attribute, Service and Controller Example, MySQL database with masked password in config, SwaggerUI, EF Core and extension to EF Core
I have upload this project template to https://github.com/Alex-1347/BackendAPI and https://marketplace.visualstudio.com/items?itemName=vb-netcom.BackendApiNetCore5VB. This project template of BackendAPI has a series future needed to any real API:
- Authentication by NET CORE 5 Middleware by JWT. Pay attention that JWT is only one method for AU, other method you can se in page HTTP Authorization. And of course, NET CORE Middleware is only one way to create JWT token, there are a lot of alternative way is, for example:
- 2020 year: VB.NET ASP.NET Core 3.1 Jwt Protected Microservices Without Mvc Controller (Project Template for VS2019) - Download from: [MyServer], [Github], [VisualStudio Marketplace]
- 2020 year: C# ASP.NET Core 3.1 Call Microservices From Blazor With Jwt Protection - Download from: [MyServer], [Github], [VisualStudio Marketplace]
- This project uses Custom attribute for marked what methods in controller have to protected. This is very common method in NET, you can see more in this page:
- 2020 year: VB.NET ASP.NET Core 3.1 Audit by custom attribute (Project Template for VS2019) - Download from: [MyServer], [Github], [VisualStudio Marketplace]
- Use jQuery Unobtrusive Validation, custom attributes for validation and validation service/controller.
- Use CustomAttribute to store metadata about model field.
- All model has custom validator with attributes and own function.
- This project included example of NET CORE WebApi controller and NET CORE Services.
- This project included AES symmetric encryption function (as NET CORE Service).
- This project included full workable and configured connection to Linux MySQL server, I don't use trash Microsoft connector to MySQL, I use Pomelo.EntityFrameworkCore.MySql. You can see in project how to configure it. My project don't need real connection to MySQL and can be started without database. To activate database need to uncomment a couple of string and fill connection string to real MySQL Server.
- I don't like (for security reason) store password to MySQL connection in appsettings.json, I masked it by AES key, and AES encryption key has been stored in code in masked form.
- You can see in project two way how to access to appsettings.json.
- Project configured to use custom port, because port 5000 usually need to frontend.
- You can see how to setup custom logger to each service or controller.
- Project contains configured SwaggerUI, this is usually mandatory service for any Backend API.
- Project contains Entity Framework Core, fully configured, you can expand it by simple way - need to include your own DbSet in ApplicationDbContext
- Project use Extension Function of EF NET CORE to mapping data from MySQL to POCO class, you can see how to do it.
- Project contains example of Action and and Lambda expression in VB, at common my site contains dozens of various example of Extension and Lambda expression in VB.NET, you can see how to do it:
- Expanding opportunities of Classic ASP.NET with generic extension function FindBaseClassRecursively.
- Set HandCursor for all ToolStripButton by Linq, Extension, Delegates, Lambda Expression and Anonymous Action.
- How to reorder DataRow with Extension function, Anonymous types, Lambda Expression and Linq Special Row Comparer.
- Amazing extension function CopyLinqDataMembersByName to expand Linq-to-SQL.
- Змінні Nullable та як обробляти DBNull з бази за допомогою Extension-функції.
- Project included instruction about testing API, no need to use Postman for testing REST API, I use light and more useful Mozilla Addon https://addons.mozilla.org/en-US/firefox/addon/restclient/
- This is project definition file with list of packages I use.
1: <Project Sdk="Microsoft.NET.Sdk.Web">
2: <PropertyGroup>
3: <TargetFramework>net5.0</TargetFramework>
4: </PropertyGroup>
5: <ItemGroup>
6: <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.5" />
7: <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.13" />
8: <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
9: <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.4" />
10: <PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
11: <PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
12: <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.11.0" />
13: </ItemGroup>
14: </Project>
And this is answer to final question - Why I still use VB.NET? See please this page Why Microsoft vilified Visual Basic ?.
- 2022 year: VB.NET BackendAPI (Net Core 5) project template with Custom Attribute, Service and Controller Example, MySQL database with masked password in config, SwaggerUI, EF Core and extension to EF Core - Download from: [MyServer], [Github], [VisualStudio Marketplace]
Comments (
)
<00>
<01>
<02>
<03>
<04>
<05>
<06>
<07>
<08>
<09>
<10>
<11>
<12>
<13>
<14>
<15>
<16>
<17>
<18>
<19>
<20>
<21>
<22>
<23>
Link to this page:
http://www.vb-net.com/BackendAPI/Index.htm
<SITEMAP> <MVC> <ASP> <NET> <DATA> <KIOSK> <FLEX> <SQL> <NOTES> <LINUX> <MONO> <FREEWARE> <DOCS> <ENG> <CHAT ME> <ABOUT ME> < THANKS ME> |