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 a MVC Project, fully functional.

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 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 the 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 demonstation, I am using the name StoreManager.

dotnet new aspnetcorehero.boilerplate -n StoreManager
powershell Zq84E3BwLc ASP.NET Core Hero Boilerplate - Quick Start Guide

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

explorer G1hamfpX1b ASP.NET Core Hero Boilerplate - Quick Start Guide

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

devenv fLm0NEpdQY ASP.NET Core Hero Boilerplate - Quick Start Guide

Once the Packages are done restoring, open up the appsettings.json of both the API and MVC Projects. Make sure that you add in 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 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 regenrate them.

With the Migrations ready, let’s update the database now.

update-database -context IdentityContext
update-database -context ApplicationDbContext
devenv jCyqWNofSD ASP.NET Core Hero Boilerplate - Quick Start Guide

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.

Ssms R5hU2OwpNv ASP.NET Core Hero Boilerplate - Quick Start Guide

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.

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.

chrome srzlshWX9N ASP.NET Core Hero Boilerplate - Quick Start Guide
chrome sbBKs0Jc1F ASP.NET Core Hero Boilerplate - Quick Start Guide

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 webapplication.

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.

chrome WspN30KX81 ASP.NET Core Hero Boilerplate - Quick Start Guide

Super Clean Dark Mode is Available too! <3

chrome baSXbFlnVX ASP.NET Core Hero Boilerplate - Quick Start Guide

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

chrome nrbUEEccL5 ASP.NET Core Hero Boilerplate - Quick Start Guide

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?

chrome WUQPTDMMxh ASP.NET Core Hero Boilerplate - Quick Start Guide

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

chrome vaInzB9vO9 ASP.NET Core Hero Boilerplate - Quick Start Guide

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

chrome mAgN0nvQUc ASP.NET Core Hero Boilerplate - Quick Start Guide

Open up the Products Page.

chrome 9HvuyePO3i ASP.NET Core Hero Boilerplate - Quick Start Guide

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

chrome dOnSV2ZE7M ASP.NET Core Hero Boilerplate - Quick Start Guide

Click Save. Done.

chrome OgfoscSLwu ASP.NET Core Hero Boilerplate - Quick Start Guide

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.

chrome EivK0GCvnT ASP.NET Core Hero Boilerplate - Quick Start Guide

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

chrome eRhVkN0mU7 1 ASP.NET Core Hero Boilerplate - Quick Start Guide

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

chrome 0sLc7mh2oO ASP.NET Core Hero Boilerplate - Quick Start Guide

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.

chrome eVkqScfKwY ASP.NET Core Hero Boilerplate - Quick Start Guide

This is how Users are mapped to Roles.

chrome foINE5SzL1 ASP.NET Core Hero Boilerplate - Quick Start Guide

MultiLingual and RTL Support Included.

chrome BFSsed69GN ASP.NET Core Hero Boilerplate - Quick Start Guide

More documentations coming soon.

Consider supporting me by buying me a coffee.

Thank you for visiting. You can now buy me a coffee by clicking the button below. Cheers!

Buy Me A Coffee

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

37 Comments

    1. 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?

    1. 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

  1. I am so excited to implement and use this solution in my future project,
    All the best for your awesome work dear Mukesh

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

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

    1. Thank you for your great work!! 🙂
      Can you answer here? How to use join with tables using the repositories? Any workaround.

  4. 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.

  5. 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.

    1. 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.

  6. 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

    1. 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

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

  8. Is it possbile to support:
    1- NSwag Swagger toolchain(something like Abp Framework in angular version abp-generate-proxy)
    2- Redis
    3- signalR

    1. 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’)

  9. 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.

      1. 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

  10. 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.

  11. 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.

  12. 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

  13. 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.

  14. 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.

  15. 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.

Ezoicreport this ad