Entity Framework Core context in separate assembly

By Dawid on (tags: ASP.NET, context, core, ef core, categories: code)

Most of example currently available on the internet shows how’s to start using ASP.NET Core and EF Core implemented in the same assembly. In the RC1 there was couple of tricks which we had to implement if we would like to have separate assembly with data model definition.

In RC2 release it’s a little bit easier. Bellow I’ll show you how you can achieve that.

This is our application context:

The most important part here is to pass options to the base class constructor. Thanks to that we can configure connection string and database provider where most of configuration and services are registered in ASP.NET Core – in Startup.cs class.

And that’s all! There is no need to create separate empty Startup class in the assembly with database context or other tricks. Like I show above, you just need to select database provider and provide connection string. Providing external service provider isn’t needed. This