/Daarto

Dapper implementation of ASP.NET Core Identity stores.

Primary LanguageC#

Daarto

The main purpose of the project is to demonstrate a custom implementation of ASP.NET Core Identity by using SQL Server and Dapper, in case you do not want to use the default implementation provided by Entity Framework. The application uses ASP.NET Core 2.1 and is built by using Visual Studio 2017 Community Edition and SQL Local DB.

Getting Started

In order to successfully run the application, the only thing you have to do is re-create the database used, in your local machine. Inside misc/scripts folder you will find a file called create_database_schema.sql. Execute this T-SQL script in SQL Server Management Studio Query Window and all the required tables will be created automatically in a database called DaartoDb. The schema is the default one, which is also used by ASP.NET Core Identity. Then run the following scripts in the order displayed below, to generate some demo data (they are random and created by using a very handy online tool called mockaroo).

One last step is to run a Gulp task in order to copy some npm packages in the wwwroot/lib. The task we need to run is called copy:libs

In Visual Studio navigate to View -> Other Windows -> Task Runner Explorer to be able to run this task easily.

When running the application use the following credentials to use an administrator's account

Logging in with the administrator role will give you the ability to access the admin dashboard.

I will try to add more features as i develop the application. If you like my work, feel free to use this project as a starting point for your own applications.

Use as Nuget package

I have published the AspNetCore.Identity.Dapper project as a NuGet package. In order to install the package use the following command.

PM> Install-Package AspNetCore.Identity.DapperOrm

In order to register the IUserStore and IRoleStore store implementations, you will need to use the AddDapperStores extension method when configuring identity in your ConfigureServices method.

// Get the connection string from appsettings.json file.
var connectionString = Configuration.GetConnectionString("DefaultConnection");
// Add and configure the default identity system that will be used in the application.
services.AddIdentity<ApplicationUser, ApplicationRole>()
        .AddUserManager<UserManager<ApplicationUser>>()
        .AddRoleManager<RoleManager<ApplicationRole>>()
        .AddSignInManager<SignInManager<ApplicationUser>>()
        .AddDapperStores(connectionString)
        .AddDefaultTokenProviders();