ASP.NET Core Hero Boilerplate – Quick Start Guide
In this post, we will talk about getting started with ASP.NET Core Hero Boilerplate Solution Template for .NET 5. Note that this Solution Template will include both a WebAPI and an MVC Project, fully functional.
NOTE: This project will not receive any further updates. If you are looking for an ASP.NET Core Web API Boilerplate (.NET 7+), please check out fullstackhero: https://fullstackhero.net/dotnet-webapi-boilerplate/general/getting-started/. And here is a reference video for setting up the .NET 7 Boilerplate: https://www.youtube.com/watch?v=a1mWRLQf9hY&t=145s&ab_channel=MukeshMurugan
Quick Links
Project Page – View the Project page here
Project Repository – https://github.com/aspnetcorehero/Boilerplate
Nuget Package – https://www.nuget.org/packages/AspNetCoreHero.Boilerplate/
Prerequisites
- Make sure you are running on the latest .NET 5 SDK (SDK 5.0 and above only). Get the latest one here.
- Visual Studio 2019 (v16.8+) ( You can check out my Installation Guide of Visual Studio 2019 Community which is completely Free to use.) Make sure that ASP.NET and web development workload is installed.
- Install the latest DOTNET & EF CLI Tools by using this command – dotnet tool install –global dotnet-ef
- I recommend that you read Onion Architecture In ASP.NET Core With CQRS – Detailed article to understand this implementation much better. This project is just an Advanced Version of the mentioned article.
- Once you are clear with Onion Architecture Implementation, you will also need to be aware of CQRS MediatR Pattern. I have written a step-by-step guide on how to implement CQRS using MediatR Library. Read it here.
Getting Started with ASP.NET Core Hero Boilerplate
Let’s install the required NuGet Package First. The download size is around 10 Mb. Open up Command Prompt and run the following command.
dotnet new --install AspNetCoreHero.Boilerplate
Now what this does is, it installs the entire Solution Template on to your machine so that you can use the template as a starting point for your upcoming projects. Let’s see how to start generating solutions and configure them.
Navigate to your Repository folder (any folder where you usually create your projects). Open up your command prompt and change the directory to your working folder. For this demonstration, I am going to create a WebApplication Solution for a Store. I will be naming it StoreManager and use the location as ‘D:\Repository\’.
cd D:\Repository\
Next, type in the following command to actually generate the Solution with your required Namespace. For this demonstration, I am using the name StoreManager.
dotnet new aspnetcorehero.boilerplate -n StoreManager

And that’s it! Your Solution is ready with all the layers of Projects. Let’s open up the Solution File in Visual Studio.

Give it a moment for Visual Studio to finish restoring all the required NuGet packages.

Once the Packages are done restoring, open up the appsettings.json of both the API and MVC Projects. Make sure that you add valid Connection strings here. Here is how I set it up for my database server (MSSQL).
"ConnectionStrings": { "ApplicationConnection": "Data Source=LAPTOP-7CS9KHVQ;Initial Catalog=StoreManager;Integrated Security=True;MultipleActiveResultSets=True", "IdentityConnection": "Data Source=LAPTOP-7CS9KHVQ;Initial Catalog=StoreManager;Integrated Security=True;MultipleActiveResultSets=True" },
Once the Connection Strings are updated, let’s add the Migrations and Update the Database. Open up the package Manager Console and Set the Startup project as the API Project. Set the Default Project as the Infrastructure project (See the red highlighted area in the screenshot below). Run the following commands.
add-migration initial2 -context ApplicationDbContext add-migration initialIdentity2 -context IdentityContext
Note that I have already added the Migrations to the Solution Template, which means you really don’t have to do the above-mentioned step to generate the Migrations. But in case you lose the Migration file, use the above commands to regenerate them.
With the Migrations ready, let’s update the database now.
update-database -context IdentityContext update-database -context ApplicationDbContext

If everything goes as expected, you will be able to see a newly created database with all the included Identity Tables and more. Default Data is also seeded.

Default Roles & Credentials
As soon you build and run your Awesome Application, default users and roles get added to the database.
Default Roles are as follows.
- SuperAdmin
- Admin
- Moderator
- Basic
Here are the credentials for the default users.
- Email – superadmin@gmail.com / Password – 123Pa$$word!
- Email – basic@gmail.com / Password – 123Pa$$word!
You can use these default credentials to generate valid JWT Tokens at the ../api/account/authenticate endpoint as well as use them to login to the MVC Application.
WebAPI Project
Here is how to Generate JWT Tokens for Authenticated User.


You can now use the token to authenticate other requests. Note that by default, all the endpoints are secured and are only accessible to authenticated users.
MVC Project.
Now, let’s take a brief look into the .NET 5 MVC Project. You will be welcomed with a login page. Note that only authenticated users can access this web application.
Both the WebAPI and MVC Projects are Independent Projects. The MVC Project DOES NOT consume the WEBAPI Endpoints.
The default user details and credentials can be found in the footer of the login page.

Super Clean Dark Mode is Available too! <3

The user gets redirected to the Dashboard once logged in successfully.

As mentioned earlier, a sample CRUD Operation is included with the project to understand the flow better. This Operation is based on AJAX Calls, Partial Views, JSON Result Rendering, jQuery Datatable, Select2 and some great UX. Gives you a near Single Page Application Feel.
Let’s start by creating a Brand. Open up Brand from the Catalog Dropdown menu in the sidebar. This is a jQueryDatable Bootstrap implementation. Looks clean, yeah?

On Creating the Create Button, the create Modal pops up. Enter in the Brand name and save it.

There you go, as simple as that. Next let’s use this brand and create a new product.

Open up the Products Page.

Add in some dummy product details and let’s select the previously added brand.

Click Save. Done.

Here is one of my favorite parts of the project – Audit Logging. A super minimal interface and package that can track all the changes done via Entity Framework Core – User wise. Pretty handy for Logging Purposes.
I have built this feature as a separate Nuget Package that you install for your other projects are well. Get the package here. Note that it comes out of the box with this Solution Template.

User Management is yet another highlight of this project. Superadmins have access to this feature.

Admin, Basic , Superadmin, Moderator are the default Roles built in to the application. You can add new Roles as well.

Every Role has a set of customizable Permissions. Superadmins by default have all the permissions. For instance, you can set the Permissions of Admin to Brand.Create which give the Admins the right to create new Brands and so on. Multiple Users can be assigned the role of Admin. You get the point.

This is how Users are mapped to Roles.

MultiLingual and RTL Support Included.

More documentations coming soon.
Thank you for all your hard work for Clean Architecture Boilerplate
Congratulations.
Thanks to you too for the feedback. Hope you liked it 😀
Awesome Mukesh!
It Will be nice a version with Blazor as a frontend…all with clean Arch.
Best wishes
Joseph
Hi Joseph, yes that’s my intention with making the API Public. I will start working on the Blazor version as soon as time allows me to. I am thinking of using mudBlazor Component Library. Any Suggestions?
Looking forward to the Blazor version.
MatBlazor or Syncfusion are good choices. 😀
Hello Mukesh,
How can I set ApplicationUser as a ForeignKey in a Entity from Core.Domain?
Hi, AuthenticatedUserService.cs gives you the currently authentication userId. Else, you could also create a userService that uses context to return a list of users. That is a also available in the UserList View. Since User Identity is an Infrastructure Concern, you would need a separate DB call for it.
Regards
thank you very much!
I am so excited to implement and use this solution in my future project,
All the best for your awesome work dear Mukesh
First, thank you for all the work you do! I see the IApplicationLayer and IDomainLayer interfaces but I don’t see where they are implemented. Can you explain the thought process behind how they are intended to be used? My other question is about the CacheKeys. Would you be able to explain what the CacheKeys are for and how I use them? I don’t see them discussed in your previous articles but maybe I missed it. Thank you!
Hi Mukesh, a few more questions related to organization for a very large rewrite of code I’m working on. We have 10+ applications that use different database schemas in an Oracle DB but all use one core schema that contain common information required by all apps such as customers, employees, projects, vendors, etc. I’m building out an API layer to access all the data. Each schema uses a different login so I’d be using different DBContext for each one. I’m curious how to go about organizing the DBContexts if I have the following database schemas:
ProdData – Common database schema that all other apps require
Annotator – DB schema for App 1
Aqua – DB schema for App 2
IGL – DB schema for App 3
I would like the API for ProdData and each application’s API to be their own solution and in separate git repos? The individual application projects would add the ProdData as a nuget package reference. I’m just not sure how that will work with DBContexts, Repositories, and the Linq queries from the applications that need to join tables across schemas? Do you think that will work? How would you go about organizing something this complex for a large API project? Thank you!
Dear Mukesh Murugan,
How can I join to table, for example : show Band name in the Product table?
Thank you for your great work!! 🙂
Can you answer here? How to use join with tables using the repositories? Any workaround.
Fantastic Murkesh!!! I was learning about Uncle Bob’s clean architecture and thought it was very good and of course, clean 🙂 I then was going to build something like this from scratch so thank you so much for creating BOTH an API & WEB version.
Awesome Mukesh! Great Work!!
In the Permissions for Admin Role there are 16 entries.
I Select the first (Permissions.Brands.View) and from the second page the 16nth (Permissions.Users.Delete) .
When I click the save button only the 16nth has the selected value equals to true.
The first ten items of the PermissionViewModel model are null (PermissionController.cs line no 57)
Why is this happening?
Am I doing something wrong?
Thank you in advance.
Hi Mukesh.
Excellent Work.
How can I use existing Database with the ASP.NET Core Hero Boilerplate?
Br,
Hi! Thanks.
I would recommend using a fresh DB. However, since this is EF Core, you can use existing DBs as well. you will need to modify the Migration’s Up and Down Transactions to match your requirement though.
Regards.
Hi Mukesh, could you please help me connect this template to oracle database?
Hi!
Sure, What’s the issue you face?
Regards
Hello Mukesh,
what is the diffrent between
asp.net boilerplate and abd
https://github.com/abpframework/abp
is it better than abd with free license?
Thanks for all the articles, got you a few cups of coffee, wish I could get my company to buy you some, your articles save me a lot of time. You have a knack for reducing a large amount of information into a concise readable format. I especially like your citing of previous works you are building on, this lends a great deal of credibility to your projects. I have compared all your templates and projects from the .net 5.0 to Dapper and EF and it is amazing how you stayed within best practices, so very, very good job. For those who doubt, check these out, Microsofts eShopOnWeb with included best practices https://github.com/dotnet/eShopOnWeb and Code-Maze CQRS pattern https://code-maze.com/cqrs-mediatr-in-aspnet-core/
Now a little detail, in your boilerplate template, the ServicesCollectionExtensions.cs options.UseSqlServer(configuration.GetConnectionString(“ApplicationConnection”) tries to obtain ApplicationConnection but the ConnectionString in AppSettings is named “DefaultConnection” throwing an error
Good Luck and Thanks Again Jeffrey
Thanks a lot for the coffees mate 🙂 And really thanks for the feedback as well 😀
I had checked the appseettings json. However I couldn’t notice the issue that you have mentioned. Could you help me out here.
Regards
Cache is not getting cleared on logout or on restarting the new session. it still brings up previous information, please suggest how to fix it.
Is it possbile to support:
1- NSwag Swagger toolchain(something like Abp Framework in angular version abp-generate-proxy)
2- Redis
3- signalR
in PermissionAuthorizationHandler.cs
var userRoles = _roleManager.Roles.Where(x => userRoleNames.Contains(x.Name));
should be .ToList();
var userRoles = _roleManager.Roles.Where(x => userRoleNames.Contains(x.Name)).ToList();
should be
var userRoles = _roleManager.Roles.Where(x => userRoleNames.Contains(x.Name)).ToList();
otherwise I get the following error
“A Command Is Already In Progress” : SELECT a.id, a.concurrencystamp, a.name, a.normalizedname FROM identity.”AspNetCore_Roles” AS a WHERE a.name IN (‘Admin’, ‘Moderator’, ‘Basic’, ‘SuperAdmin’)
Hi Mukesh,
Really a good work and thank you for deep dive into project architecture information.
After reading all the articles provided by you. I have started implementing in my new project.
Can we call webapi from mvc project in this given architecture? If yes then please provide some tips or demo code for the same.
Hi Thanks!
This Project doesnt have the MVC Httpclient that can consume the existing API. Rather, the MVC project directly talks to the application layer. However I am working on a new project that works in the same way you have suggested. It’s still under construction now.https://github.com/fullstackhero/aspnet-core-webapi-boilerplate This is supposedly the API project
Regards
Hi Mukesh,
Just wanted to confirm that if in your mvc project if I remove Identity Area and make my custom logic for register and also if I make changes in existing mvc project which will consume API will that work?
Or its better to make a separate MVC project and consume APIs of this project?
Thanks,
Utsav
Hi Mukesh,
This is very Awesome article and I appreciate your hard work for Clean Architecture Boilerplate.
I am so happy with this solution but I have few question regarding this solution.
1) It is support the multi-Tenancy? If Yes(please explain me) If No(Please explain me how can I implement schema-based or multi-Tenancy).
2) Can you suggest me how can I display the Permissions in Tree view format like (parent and child menu based)
Similar to below
https://www.jqueryscript.net/demo/jQuery-Plugin-For-Displaying-A-Tree-Of-Data-In-A-Table-treetable/
or you can suggest any tree view format.
Thanks in advance.
Hi Mukesh,
Thank you so much for all your hard work. I’ve learned a lot about clean architecture from this template. I noticed that the MVC does not consume the API. Do you know if there is any way that I can consume the API? I’ve tried using multiple projects to start up the solution and removed the authentication requirement in the API but my AJAX call in the MVC does not seem to work. The API does work in swagger though. Thanks again for your help! I’m learning a lot and appreciate all of your hard work.
Hi Sir,
Is there any doc with steps which we can follow to create new pages in this template?
Thanks!
How to translate?
Hi Mukesh,
Thank you very much for your article I have issue while calling Stored Procedure could you please help me to figure out how would I do this?
Thank you,
Jitendra
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)
Dont know why this is happening. Have checked the connection and is Ok. Still when using update command the error is comming.
I’m using the mvc layer and after I add this to my project when selecting manage user role on a user it gives me this error InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
Hi Mukesh,
Thanks alot for this article it really helped me a lot.
I wish I could have a detailed CRUD documentation as its bit hard for me to just to have a look at code and to figure our to develop my custom form here.
It would be appreciable if you could provide few pointers how to do it.
I am utilizing sendinblue.net as my email sender. I cannot figure out why it will not allow me to send emails.
My setup for credentials is as follows in the AppSettings.
“MailSettings”: {
“From”: “{UserName Entered Here}”,
“Host”: “smtp-relay.sendinblue.com”,
“Port”: 587,
“UserName”: “{UserName Entered Here”,
“Password”: “XXXXXXXXtLhjdcZG”,
“DisplayName”: “SGLEMC – Lubbock”
},
It works in my other sites….
Mukesh, I love, love, love this template. It has saved me so much time and headaches with putting together a new project I am starting to work on.
I am sending you TWO (more) Coffee’s
Hi Mukesh.
Excellent Work. Thank you so much for this template
but having issue when i updated this project version to .net 7 bcoz .net 5 was not installed at my end so and updated all packages to latest versions.
after this i checked not able to save in brand table –
await _brandRepository.InsertAsync(product);
await _unitOfWork.Commit(cancellationToken);
i noticed from insertAsync Brand.Id is not returning and when execute commit line its throwing exception
One or more errors occurred. (Method not found: ‘System.String Microsoft.EntityFrameworkCore.Metadata.IPropertyBase.get_Name()’.)
please help on this
thanks you