LernenderCorpDotNetMicroserviceGenerator 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet new install LernenderCorpDotNetMicroserviceGenerator::1.0.3
This package contains a .NET Template Package you can call from the shell/command line.

Lernender Corp .NET Microservice Generator

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!!!!

  1. Microsoft Windows Pro
  2. Installed .NET SDK 7.0
  3. Install Powershell 7.3 for Windows
  4. Microsoft SQL Server Management Studio (latest)
  5. SQL Server Database
  6. Database DDL created and validated for all entities and constraints
  7. SQL Server User Account & Password (i.e. sa account)
  8. Visual Studio Professional 2017 (15.9.57)
  9. Visual Studio Build Tools 2017 (15.9.57)
  10. AWS Account (used in YAML deployment scripts)
  11. AWS ECR Repository (used in YAML deployment scripts)

Install "LernenderCorpDotNetMicroserviceGenerator" Nuget Package

Using Package Manager;
Search for PackageId: "LernenderCorpDotNetMicroserviceGenerator" 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. Database

In order for this Microservice Generator to work properly. It must have a valid SQL Server Database. Effectively, the Microservice Generator uses a database as a driver to know how to construct the various layers of the Microservice Api (i..e Controller, Service and Repository).

WARNING:

With out a valid database this Microservice Generator will not work!!! Before moving forward make sure to define a database with valid login administrative credentials. This database and corresponding credentials will be used in the followig steps.

3. Change to Working Directory

Once your template has been installed and verified then change directory to your development folder (example c:\dev)

4. 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 lnmsapi 
--namespace <namespace>
--output <namespace>
--sqlServer <sqlServer>
--sqlDatabase <sqlDatabase>
--user <usr>
--passwd <passwd>
--dbContext <dbContext>
--awsAccountId <awsAccountId>
--awsECRRepository <awsECRRepository>
--azureDevOpsServiceConnection <service connection name>
--dry-run
Example:
-----------------------------------------------------------------

C:> dotnet new lnmsapi 
--namespace {namespace} 
--output {namespace} 
--sqlServer {sqlServer}
--sqlDatabase {sqlDatabase} 
--user {usr}
--passwd {passwd}
--dbContext {dbContext}
--awsAccountId {awsAccountId}
--awsECRRepository {awsECRRepository}
--azureDevOpsServiceConnection {azureDevOpsServiceConnection}
--dry-run

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:

5. Run Database Context Powershell Script (GenerateContext.ps1)

[Project Folder] >cd {namespace}.Microservice\{namespace}.Microservice.Repository

Where {namespace} is defined by what was given at the command line Execute Powershell Script (GenerateContext.ps1)

{namespace}.Microservice\{namespace}.Microservice.Repository > .\GenerateContext.ps1

6. Run Powershell Script (Generate.ps1)

  • Execute Powershell Script (Generate.ps1)
[Project Folder] > .\Generate.ps1

7. 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 examine 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 repository APIs must be implemented by the developer.

Docker Build & Run

When attempting to run docker command you need to be in the root directory of the project.

The following commands are listed here for you to use:

> docker build -t {namespace} .
> docker run --env-file ./.env  -p 8000:80 -p 443:443 -p 1433:1433 -t {namespace}

NOTE: The docker images is intended to ruin in Production mode (i.e. ASPNET_ENVIRONMENT=Production). If you wish to run your docker container in development mode append an environment variable.

Example:

> docker build -t {namespace} .
> docker run --env-file ./.env -e "ASPNET_ENVIRONMENT=Production"  -p 8000:80 -p 443:443 -p 1433:1433 -t {namespace}

Microsoft Azure DevOps

The template also comes with a YAML file for both windows and linux platforms.

When setting up CI/CD build simply chooses which platform you want (i.e. windows or linux). The image will be build and deployed to Elastic Container Registry (ECR) provided correct AWS account and Registry names are specified.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.10 5,077 9/30/2023
1.0.9 1,198 9/29/2023
1.0.8 1,099 9/29/2023
1.0.7 1,204 9/28/2023
1.0.6 1,172 9/23/2023
1.0.5 1,306 9/23/2023
1.0.4 1,293 9/23/2023
1.0.3 1,173 9/23/2023
1.0.2 1,219 8/8/2023
1.0.1 1,161 8/8/2023
1.0.0 1,364 8/7/2023