Add EF6 to a razor class library project to be shared by many BLAZOR projects?

270 views Asked by At

Is it possible to add EF6 to a razor class library ? The goal is to have many components shared by other BLAZOR projects, but a lot of these controls require access to the database, which is the same for all the projects inside this solution. Also, I assume that the db access will be via a controller since it is not possible to inject as a service. Is this correct ?

1

There are 1 answers

0
Henk Holterman On BEST ANSWER

Is it possible to add EF6 to a razor class library ?

Yes but you would immediately restrict that library ro Blazor Server side.

a lot of these controls require access to the database

That is not a great architecture

I assume that the db access will be via a controller

Not necessary with server-side, you can inject a DbContext into your pages and components

When you have components that depend strongly on your Entity classes and business logic then a Razor Class Library is maybe not the best choice.

When you do want this, create a specific layer with storage-agnostic models and interfaces for services. It's the 2 layers at the core in the Onion architecture.

Your component can depend on the interfaces and the main app can implement them.