LernenderCorpMicroserviceGeneratorAspNetCore 1.0.0
See the version list below for details.
dotnet new install LernenderCorpMicroserviceGeneratorAspNetCore::1.0.0
LernenderCorp.Microservice.Generator.AspNetCore
Overview
This project is intented to be used by Software Engineers to help facilitate scaffolding of Microservices. The project utilizes 'dotnet ef dbcontext scaffold' to build out models that are reflective on table entities defined within a Microsoft SQL Server Database.
Moreover, using Microsoft's T4 Templating Engine (Microsoft.VisualStudio.TextTemplating) a complete set of Controllers, Services, and Repositories will be automatically created.
Additionally, a Dockerfile was created to help facilitate the need to containerize the Microsoft Project which can subsequently pushed and consumed using AWS Elastic Container Service and/or Kubernetes.
Author
Author: Lovelidge, Shawn
License
This project is licensed with the MIT license.
Prerequisites
The following prerequisites are required to use this package.
- Microsoft Windows Pro
- Installed .NET SDK 7.0
- Install Powershell 7.3 for Windows
Install "LernenderCorpMicroserviceGeneratorAspNetCore" Nuget Package
Using Package Manager;
Search for PackageId: "LernenderCorpMicroserviceGeneratorAspNetCore" and install this package.
Once installed follow the remaining steps.
1. Verify Installed Template
To see all installed dotnet templates:
-----------------------------------------------------
c:> dotnet new list
Specific Template (i.e. 'Lernender Corp Microservice Generator AspNetCore'):
-----------------------------------------------------
C:> dotnet new list | findstr -i Lernender
2. Change to Working Directory
Once your template has been installed and verified then change directory to your development folder (example c:\dev)
3. Create MicroService Project
Now you can being using the template to create your first Microservice Project. Execute the dotnet CLI statement listed below.
SYNTAX:
-----------------------------------------------------------------
dotnet new <template shortname> --output <project namespace> --dbContext <dbContext> --sqlDatabase <database name> --sqlServer <IP Address>
Example:
-----------------------------------------------------------------
C:> dotnet new lnmsapi -n {namespace} -o {output directory} --dbContext {dbcontext} --sqlDatabase {database} --sqlServer {server} --passwd {password}
Option | Definition |
---|---|
namespace | Give a namespace for your microservice. Typically this is your company name followed by the name of your project (i.e. Ln.Microservice) |
output directory | specify the directory where the project will be created. (note: omit back-slash or forward-slash) |
dbcontext | Give a name for the dbContext file that will be created (i.e. LnContext) |
database | Provide the name of the Microsoft SQL Database that will be used to generate the layers of this project |
server | Provide the server name where the database is stored. This can be an IP address |
password | Provide the password for connecting to the database. |
NOTE:
The project should have been created after executing step 3.
Change directory to the new project folder.
Following the instructions in the next step:
4. Run Powershell Script (RunT4.ps1)
- Execute Powershell Script (RunT4.ps1)
[Project Folder] > .\RunT4.ps1
5. Build the Project in Visual Studio 2023
If everything went well your Microservice project has been scaffold out and your entire rest API has been created. Open the solution file in your project folder and take time to examin the code in the Repository, Service, and Controller layers.
WARNING:
The project should work out of the box with one small caveat namely, the Select() calls for all endpoints need to be defined by the developer. Because the domain context of the table entities are not known until runtime it is impossible to accurately generate a fully qualified lambda expression that will select all the rows in a table. Therefore, the developer must supply this code for all Select() methods of each entity within the repository layer.
6. Docker Images
The project comes with a fully qualified dockerfile and the image can built using this file (located at the root of the Project folder).
NOTE:
In order for the docker container to function properly. The developer must replace the setting defined in the 'appsettings.json' located in the ***.Api web project with the settings defined in the 'appsettings.Docker.json' file. This must be done BEFORE the docker image is created.
-
net7.0
- Microsoft.VisualStudio.TextTemplating (>= 17.5.33428.366)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.