EntityFramework Core – Add an implementation of IDesignTimeDbContextFactory


Your DbContext in a separate project – class library project. You are trying to add new migration and update database, and you are running into this error:

Unable to create an object of type ‘CodingBlastDbContext’. Add an implementation of ‘IDesignTimeDbContextFactory’ to the project, or see https://go.microsoft.com/fwlink/?linkid=851728 for additional patterns supported at design time.



So you need to implement this interface, and you are not sure how to do it.

You can add a class that implements IDesignTimeDbContextFactory inside of your Web project.

Here is the sample code:


Then, navigate to your Database project and run the following from command line:

-s stands for startup project and ../Web/ is the location of my web/startup project.



The full example is available on GitHub.

Ibrahim Šuta

Software Engineer, Mentor and Consultant interested and specialising in ASP.NET Core, C#, JavaScript, Angular, React.js. Experienced in MeteorJS, Node.js, ASP.NET, Windows Forms and Web Forms as well.