Use Azure CosmosDB as database
Prerequisites
Azure CosmosDB instance is created. The following instruction assumes there is a collection named User exists in database named UserManagement.
PM> Install-Package Microsoft.EntityFrameworkCore.Cosmos
Register user management module in ASP.NET core project
public class Startup
{
//...
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddUserManagement().UseEFCore(
new EFCoreOptions
{
DbContextOptionsBuilder = options => options.UseCosmos("***Connection string***", "UserManagement"),
ModelBuilder = (modelBuilder) => modelBuilder.HasDefaultContainer("User"),
});
//...
}
}
Create a super admin in database.
The following is a user record template. Replace "***" with the real value. Id is the primary key and unique.
Create a container with the partition key set to "__partitionKey" in Azure Cosmos DB.
NOTE:
Discriminatorandidare two field managed by EF Core.idis a string in the format of[Discriminator]|[Id]. For user record,Discriminatoris a constant - "User".
{
"Id": "u1",
"Active": true,
"CreatedBy": "***",
"CreatedOnUtc": "***",
"Deleted": false,
"Description": "***",
"Discriminator": "User",
"Email": "***",
"FirstName": "***",
"LastName": "***",
"SuperAdmin": true,
"UpdatedBy": "***",
"UpdatedOnUtc": "***",
"VeracityId": "***",
"id": "User|u1"
}