Configuring Entity Framework Core
Since database handling is confined within a dedicated application layer, it is good practice to define your Entity Framework Core (DbContext
) in a separate library. Accordingly, we need to define a .NET class library project. As we discussed in the Book use case – understanding the main types of .NET projects section of Chapter 2, Non-Functional Requirements, we have two different kinds of library projects: .NET Standard and .NET (Core).
While .NET libraries are tied to a specific .NET Core version, .NET Standard 2.0 libraries have a wide range of applications since they work with any .NET version greater than 2.0 and also with the old .NET Framework 4.7 and above.
Since our library is not a general-purpose library (it’s just a component of a specific .NET 6 application), instead of choosing a .NET Standard library project, we can simply choose a .NET 6 library. Our .NET 6 library project can be created and prepared as follows...