Entity Framework Core context in separate assembly

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.

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 UseInternalServiceProvider(serviceProvider) is new in RC2, you can get more information’s about it here.