Hi, today I am going to take you through a simple dot Net Core API backend and Angular 7 frontend Authentication system. This is the first post of a series of post as I build an e-commerce platform using dot net and Angular.


Your new AutheticationContext class will extend IdentityDbContext

Then create a constructor and pass in the DbContextOptions as a parameter in the new constructor and the Base class constructor.
DbContextOptions takes the DB provider and the connectionstring as parameters. we use Dependency injection
Dependency Injection – In Startup.cs in your ConfigureServices method adds this code. There will be no need to use new to create an instance of AuthenticationContext class when you need to use it
services.AddDbContext<AuthenticationContext>(options => options.UseSqlServer(Configuration.GetConnectionString("IdentityConnection")));
NB UseSqlServer will throw an error you can fix it as below
In your NuGet Manager run this command
Install-Package Microsoft.EntityFrameworkCore.SqlServer
You will need to create the connectionstring in your appsettings.json
"ConnectionString": {
"IdentityConnection": "Server=DESKTOP-G3UF4QR\\SQLEXPRESS; Database=tenderSA; Trusted_Connection=True; MultipleActiveResultSets=True"
}
Customising Identity User
Create a model class that extends/ inherits IndentityUser Class. Then create a new property
//customising column data type
[Column(TypeName = "nvarchar(100)")]
public string Fullname { get; set; }
Add a property in your AutheticationContext class
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
Add Migrations
In your package manager console run this command
Add-Migration "intial"
NB if that fails install this
install-package Microsoft.EntityFrameworkCore.Tools