Blog

WebAPI (ASP.NET Core API NTier)

This stencil is based on the article - Developing Great Web APIs Architectures w/ ASP.NET Core 2.1 given by Chris Woodruff at QCon.

The design is based on the following and uses very good standard practices:

  • Single Responsibility Principle simplifies implementation and design
  • The Ports and Adapter Pattern decouples business logic from other dependencies
  • Decoupled architecture makes testing much easier and more robust

This stencil will generate the same code used in this presentation. However, the beauty of stencils in CodeStencil is that you can swap and use your own database, define the name of your project, namespaces, etc. and the generated code will automatically use these.

The solution and all code from this article's examples can be found here in Chris' GitHub repository ChinookASPNETCoreAPIHex.

The stencil for this example can be downloaded from here: WebApi on github

These are a few thing to note about this Stencil:

  1. It requires .NET Framework 2.2
  2. It doesn't support non-integer primary keys. So using it with a database like the Northwind database which has the primary keys of the Customers and Territories tables using  nchar/nvarchar will generate errors.
  3. Your database source has to be a server, not a file like a sqlite or Sql Server Compact file.
  4. The Chinook.DataDapper project is not included.
  5. The Chinook.DataEFCoreCmpldQry is not included.
  6. The unit test related projects are not included.

 

Steps to try this out:

(1) Download and Install the CodeStencil Application.

Note: If you are using BitDefender Anti-virus, it may prevent the installation from finishing.

If this happens, click on the "View Details" and switch on to allow Setup/Uninstall to continue, then click "Retry" 

The application should be installed under the Program group - Zera Systems Codestencil/Codestencil 

 

(2) Download the WebAPI Stencil from github: https://github.com/codetstencil/stencils/blob/master/WebAPI.codestencil.zip

(3) Register(Install) the Stencil.

 

(4) Create a new project. Make sure you Select the WebAPI Stencil:

See Creating a Project

(5) Import a database Schema

  

 

 Select all the tables and "Import Schema" 

 

(6) Click on the "Generate" button to start the code generation process

 

(7) Navigate to the folder that contains the generated code after the generation is complete:

Note: The actual folder will be something like: D:\generated\codestencil\Chinook\src\NorthWind\NorthWind.API depending on where your code is generated. 

 

(8) Open the command prompt in the Nothwind.API folder and call "dotnet run" from there to start the kestrel server:

 

(9) Test the api by typing: "http://localhost:5027/api/artist" in the browser. 

 

×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

ASP .NET Razor Stencil Released.
CodeStencil - Another app to add to your tool ches...
 

Comments

No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Tuesday, 19 March 2024
Instant SSL Pro