How to Extend MainProjectDataContext & use it in RCL project?
I have a blazor server project as my main project with a configured dataContext called forexample : MainProjectDataContext.
Now i have a razor class library project which has a reference to my main blazor server project. in my rcl project i've added some classes as poco (without define any dataContext) to handle database transactions.
Now i have a some questions?
- How to extend my MainProjectDataContext in rcl project to handle database transactions for my new classes that i've created in my rcl project?
- how to add my new rcl dataContext to service providers & inject it into my razor files (with some options which i've configured in my main blazor server porject such as connectionString, ...)?
I will be grateful if you show with an example code.
Thanks in advance
Hi @Hamed Vaziri
Razor views, pages, controllers, page models, Razor components, View components, and data models can be built into a Razor class library (RCL). More detail information, see Create reusable UI using the Razor class library project in ASP.NET Core
For the DbContext, as Bruce said, you can create a Shared project (with EF core and DbContext) for it, then add the Shared project reference in the RCL and Main project.
Sign in to comment