Adding the DbSeeder to Startup.cs

Our next task will be to add the DbSeeder to our Startup class. Since it's a static class, we will be able to use it anywhere, but we need an instance of our ApplicationDbContext; it would be great to get that using Dependency Injection.

Theoretically speaking, we can add a new parameter in the Configure() method, as follows:

[...]public void Configure(IApplicationBuilder app, IHostingEnvironment env,     ApplicationDbContext dbContext){    [...]    DbSeeder.Seed(dbContext);}[...]

This will indeed instantiate it through DI and get it done without drawbacks. However, we really don't want to alter the Configure method default parameter list, even if it won't affect our application.

We can achieve the same outcome in ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.