DotNetBrightener.WebApi.GenericCRUD.Generator 2024.0.1-alpha-3

This is a prerelease version of DotNetBrightener.WebApi.GenericCRUD.Generator.
There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetBrightener.WebApi.GenericCRUD.Generator --version 2024.0.1-alpha-3
                    
NuGet\Install-Package DotNetBrightener.WebApi.GenericCRUD.Generator -Version 2024.0.1-alpha-3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetBrightener.WebApi.GenericCRUD.Generator" Version="2024.0.1-alpha-3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetBrightener.WebApi.GenericCRUD.Generator" Version="2024.0.1-alpha-3" />
                    
Directory.Packages.props
<PackageReference Include="DotNetBrightener.WebApi.GenericCRUD.Generator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetBrightener.WebApi.GenericCRUD.Generator --version 2024.0.1-alpha-3
                    
#r "nuget: DotNetBrightener.WebApi.GenericCRUD.Generator, 2024.0.1-alpha-3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotNetBrightener.WebApi.GenericCRUD.Generator@2024.0.1-alpha-3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetBrightener.WebApi.GenericCRUD.Generator&version=2024.0.1-alpha-3&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=DotNetBrightener.WebApi.GenericCRUD.Generator&version=2024.0.1-alpha-3&prerelease
                    
Install as a Cake Tool

Code Generator for Centralized CRUD WebAPI in ASP.NET Core Applications

© 2024 DotNet Brightener

Getting Started

Create new project

You can create the project in Visual Studio for your convenience. You can put everything into one single WebAPI project, but it's recommended not to do that, instead, you should separate the project into different libraries. The suggestion is as the following table

Project Name Project Type Purpose
{YourProject}.WebAPI WebAPI The entry point of the application
{YourProject}.Core or {YourProject}.Entities Class Library The library that contains only the entities needed for your application
{YourProject}.Services Class Library The library that contains business logics and CRUD auto generated classes
{YourProject}.Database Class Library The library that holds the database context to communicate with the database

If you like CLI, you can follow the instruction below.

  1. Create a new .NET 8 WebAPI project:
dotnet new webapi -n {your-project-name} -f net8.0
dotnet new classlib -n {your-project-name}.Database -f net8.0
dotnet new sln --name {your-project-name}
dotnet sln {your-project-name}.sln add {your-project-name}\\{your-project-name}.csproj
dotnet sln {your-project-name}.sln add {your-project-name}.Database\\{your-project-name}.Database.csproj
  1. If needed to separate the entity definitions to a different library, create new class library project
dotnet new classlib -n {your-project-name}.Core -f net8.0
dotnet sln {your-project-name}.sln add {your-project-name}.Core\\{your-project-name}.Core.csproj
  1. If needed to separate the service layer, create new class library project
dotnet new classlib -n {your-project-name}.Services -f net8.0
dotnet sln {your-project-name}.sln add {your-project-name}.Services\\{your-project-name}.Services.csproj

Now you can open the solution in Visual Studio.

Add Generic CRUD and its Generator Library

1. Add CRUD libraries

Add the following packages to the projects, following the instruction below

Package Name Project
DotNetBrightener.WebApi.GenericCRUD Web API
DotNetBrightener.WebApi.GenericCRUD.Generator Web API, Service
DotNetBrightener.DataAccess.Abstractions Core (Entity)
DotNetBrightener.DataAccess.EF Database

2. Update the settings to enable code generator

Open the csproj files and update the <PackageReference> of the Generator library with the following

<ItemGroup>
	<PackageReference Include="DotNetBrightener.WebApi.GenericCRUD.Generator"
					  Version="{current-version-of-the-library}"
					  OutputItemType="Analyzer"
					  ReferenceOutputAssembly="false" />
</ItemGroup>

The change is to add

	OutputItemType="Analyzer"
	ReferenceOutputAssembly="false"

to the XML tag, that enables the auto generate code for the projects.

Create first entity

The entities must inherit from BaseEntity or BaseEntityWithAuditInfo from the DotNetBrightener.DataAccess.Abstractions library. Create any entity into the Core or Entity project.

Example:

using DotNetBrightener.DataAccess.Models;
 
namespace CRUDWebApiWithGeneratorDemo.Core.Entities;

public class Product: BaseEntity
{
	[MaxLength(255)]
    public string Name { get; set; }

	// omitted code
}

The Entity/Core project should only contain the entities without any other logics

Configure Code Generator for Service Project

At the root of Service project, create a class CRUDDataServiceGeneratorRegistration.cs with the following content

using CRUDWebApiWithGeneratorDemo.Core.Entities;
 
namespace CRUDWebApiWithGeneratorDemo.Services;
 
public class CRUDDataServiceGeneratorRegistration
{
    public List<Type> Entities =
    [
		// provide all entities that need to generate CRUD data service for
        typeof(Product),
        typeof(ProductCategory)
    ];
}

The name CRUDDataServiceGeneratorRegistration is strictly required as the generator library will look for that file in order to understand what to generate.

In the Entities list in the class, provide all the entities that needed to generate the CRUD data service interfaces and classes.

Configure Code Generator for WebAPI Project

At the root of WebAPI project, create a class CRUDWebApiGeneratorRegistration.cs with the following content

public class CRUDWebApiGeneratorRegistration
{
	// reference the CRUDDataServiceGeneratorRegistration from Service project
    Type DataServiceRegistrationType = typeof(CRUDDataServiceGeneratorRegistration);
 
    public List<Type> Entities =
    [
		// provide all entities that need to generate CRUD API Controllers for
		// Some entities related to Authorization / Authentication / Security should be ignored
        typeof(Product),
        typeof(ProductCategory)
    ];
}

The name CRUDWebApiGeneratorRegistration is strictly required as the generator library will look for that file in order to understand what to generate.

In the Entities list in the class, provide all the entities that needed to generate the CRUD Web API Controllers for.

Build and Run Project

As you followed the instruction so far, upon building and running the project, the needed classes will be automatically generated. By default, .NET WebAPI project includes the OpenAPI library, which will detect the available APIs and you can see the following when the project is launch:

![[swagger_screenshot.png]]

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2025.0.10-preview-581 240 11/11/2025
2025.0.10-preview-559 170 10/29/2025
2025.0.10-preview-557 168 10/27/2025
2025.0.9 161 10/26/2025
2025.0.9-preview-553 156 10/26/2025
2025.0.9-preview-539 104 10/12/2025
2025.0.9-preview-535 159 10/8/2025
2025.0.9-preview-509 175 10/2/2025
2025.0.9-preview-508 164 10/2/2025
2025.0.9-preview-487 184 9/29/2025
2025.0.9-preview-481 167 9/29/2025
2025.0.9-preview-473 142 9/28/2025
2025.0.8 179 9/23/2025
2025.0.6 167 9/22/2025
2025.0.6-preview-455 179 9/22/2025
2025.0.6-preview-454 301 9/17/2025
2025.0.6-preview-441 141 9/14/2025
2025.0.6-preview-440 139 9/14/2025
2025.0.6-preview-406 173 9/2/2025
2025.0.6-preview-401 152 9/2/2025
2025.0.6-preview-400 164 9/2/2025
2025.0.6-preview-369 209 8/27/2025
2025.0.6-preview-368 202 8/27/2025
2025.0.6-preview-334 187 8/18/2025
2025.0.6-preview-333 164 7/27/2025
2025.0.6-preview-332 478 7/24/2025
2025.0.6-preview-331 493 7/24/2025
2025.0.6-preview-328 491 7/24/2025
2025.0.6-preview-327 342 7/21/2025
2025.0.6-preview-326 334 7/21/2025
2025.0.6-preview-325 244 7/20/2025
2025.0.6-preview-324 257 7/20/2025
2025.0.6-preview-322 264 7/20/2025
2025.0.6-preview-321 254 7/19/2025
2025.0.6-preview-320 245 7/19/2025
2025.0.6-preview-319 164 7/17/2025
2025.0.6-preview-317 159 7/17/2025
2025.0.6-preview-316 163 7/17/2025
2025.0.6-preview-315 151 7/17/2025
2025.0.6-preview-314 166 7/17/2025
2025.0.6-preview-313 163 7/17/2025
2025.0.6-preview-312 179 7/16/2025
2025.0.5 181 7/10/2025
2025.0.5-preview-307 101 7/5/2025
2025.0.4 94 7/5/2025
2025.0.4-preview-305 101 7/4/2025
2025.0.4-preview-304 164 7/1/2025
2025.0.4-preview-299 152 5/31/2025
2025.0.4-preview-298 124 5/30/2025
2025.0.4-preview-296 158 5/30/2025
2025.0.4-preview-295 168 5/29/2025
2025.0.4-preview-293 163 5/26/2025
2025.0.4-preview-292 173 5/26/2025
2025.0.3 148 2/10/2025
2025.0.3-preview-288 140 2/10/2025
2025.0.2 142 1/21/2025
2025.0.2-preview-278 111 1/21/2025
2025.0.2-preview-277 147 12/16/2024
2025.0.1-rc-243301701 383 11/25/2024
2024.0.14.6 135 11/25/2024
2024.0.14.6-rc-243031001 210 10/29/2024
2024.0.14.6-rc-243030701 114 10/29/2024
2024.0.14.6-rc-242840501 126 10/10/2024
2024.0.14.6-rc-242820305 108 10/8/2024
2024.0.14.6-rc-242771401 206 10/3/2024
2024.0.14.6-rc-242770501 124 10/3/2024
2024.0.14.6-rc-242770201 125 10/3/2024
2024.0.14.6-rc-242761801 119 10/2/2024
2024.0.14.6-rc-242761601 135 10/2/2024
2024.0.14.6-rc-242761501 123 10/2/2024
2024.0.14.6-rc-242761401 122 10/2/2024
2024.0.14.6-rc-242760701 130 10/2/2024
2024.0.14.6-rc-242751002 127 10/1/2024
2024.0.14.6-rc-242750901 145 10/1/2024
2024.0.14.6-rc-242750502 116 10/1/2024
2024.0.14.6-rc-242750201 130 10/1/2024
2024.0.14.6-rc-242741501 109 9/30/2024
2024.0.14.6-rc-242730701 138 9/29/2024
2024.0.14.6-preview-2730501 124 9/29/2024
2024.0.14.6-preview-2701501 157 9/26/2024
2024.0.14.6-preview-2620901 162 9/18/2024
2024.0.14.6-preview-2570701 131 9/13/2024
2024.0.14.6-preview-2510703 195 9/7/2024
2024.0.14.6-preview-2480501 134 9/4/2024
2024.0.14.6-preview-2430401 162 8/30/2024
2024.0.14.6-preview-242730701 110 9/29/2024
2024.0.14.6-preview-2421703 132 8/29/2024
2024.0.14.6-preview-2421701 125 8/29/2024
2024.0.14.6-preview-2420901 121 8/29/2024
2024.0.14.6-preview-2390101 148 8/26/2024
2024.0.14.6-preview-2381603 157 8/25/2024
2024.0.14.6-preview-2341601 159 8/21/2024
2024.0.14.6-preview-2321602 159 8/20/2024
2024.0.14.6-preview-2190801 171 8/6/2024
2024.0.14.6-preview-2041501 102 7/22/2024
2024.0.14.6-preview-1920603 174 7/10/2024
2024.0.14.6-preview-1920301 138 7/10/2024
2024.0.14.6-preview-1911302 103 7/9/2024
2024.0.14.6-preview-1901001 150 7/8/2024
2024.0.14.6-preview-1900901 118 7/8/2024
2024.0.14.6-preview-1900801 138 7/8/2024
2024.0.14.6-preview-1860304 122 7/4/2024
2024.0.14.5 191 7/1/2024
2024.0.14.5-preview-1811601 150 6/29/2024
2024.0.14.5-preview-1810501 142 6/29/2024
2024.0.14.5-preview-180132 139 6/28/2024
2024.0.14.5-preview-180131 151 6/28/2024
2024.0.14.5-preview-180121 140 6/28/2024
2024.0.14.4 165 6/27/2024
2024.0.14.4-preview-7 136 6/27/2024
2024.0.14.3 143 6/21/2024
2024.0.14.1 160 6/6/2024
2024.0.14.1-preview 117 6/6/2024
2024.0.13.8-preview 134 6/6/2024
2024.0.13.1-preview-0146 138 6/6/2024
2024.0.12.15803-preview-03 148 6/6/2024
2024.0.12.15608 167 6/4/2024
2024.0.12.15515 210 6/3/2024
2024.0.12.15220 149 5/31/2024
2024.0.12.15220-alpha31-240... 130 5/31/2024
2024.0.12.14911 167 5/28/2024
2024.0.12.14910-alpha28-240... 132 5/28/2024
2024.0.12.14823 162 5/27/2024
2024.0.12.14522-alpha7-2405... 127 5/24/2024
2024.0.12.14514-alpha6-2405... 138 5/24/2024
2024.0.12.14511 173 5/24/2024
2024.0.12.14314 186 5/22/2024
2024.0.12.14114 191 5/20/2024
2024.0.12.12815 175 5/7/2024
2024.0.12.12814 160 5/7/2024
2024.0.12.12721 153 5/6/2024
2024.0.12.12702 173 5/5/2024
2024.0.12.12622 169 5/5/2024
2024.0.12.12514 172 5/4/2024
2024.0.12.12512 174 5/4/2024
2024.0.12.12510 188 5/4/2024
2024.0.12.12420 135 5/3/2024
2024.0.12.12319 119 5/2/2024
2024.0.12.12319-rc-2405021801 99 5/2/2024
2024.0.12.12318 128 5/2/2024
2024.0.12.12215 133 5/1/2024
2024.0.12.12011 154 4/29/2024
2024.0.12.11720 174 4/26/2024
2024.0.12.11719 171 4/26/2024
2024.0.12.11621 169 4/25/2024
2024.0.12.11523 175 4/24/2024
2024.0.12.11522 157 4/24/2024
2024.0.12.11417 175 4/23/2024
2024.0.12.11400 155 4/22/2024
2024.0.12.11316 164 4/22/2024
2024.0.11.10220 161 4/11/2024
2024.0.11.10120 155 4/10/2024
2024.0.11.10119 152 4/10/2024
2024.0.11.10115 148 4/10/2024
2024.0.11.9914 165 4/8/2024
2024.0.11.9901 172 4/7/2024
2024.0.11.9823 171 4/7/2024
2024.0.11.9401 159 4/2/2024
2024.0.11.9301 151 4/1/2024
2024.0.11.9206 156 3/31/2024
2024.0.11.9205 150 3/31/2024
2024.0.11.8200 179 3/21/2024
2024.0.11.8122 155 3/21/2024
2024.0.11.8120 178 3/21/2024
2024.0.11.7320 168 3/13/2024
2024.0.11.7316 177 3/13/2024
2024.0.11.7310 161 3/13/2024
2024.0.11 166 3/13/2024
2024.0.10 172 3/3/2024
2024.0.9 161 2/27/2024
2024.0.8 175 2/1/2024
2024.0.7 161 1/26/2024
2024.0.6 149 1/25/2024
2024.0.5 146 1/24/2024
2024.0.4 147 1/24/2024
2024.0.3 161 1/22/2024
2024.0.2 175 1/10/2024
2024.0.1 177 1/9/2024
2024.0.1-alpha-3 141 1/9/2024
2024.0.1-alpha-2 147 1/9/2024
2024.0.1-alpha-1 129 1/9/2024