Search code examples
asp.netasp.net-core.net-corerazorrazor-pages

is it possible to using razor class library for all web projects?


because of the ease of using razor class library and modularity, I decide to use it instead of the regular class library but the solution is, is it possible to write all core or data layer code inside different razor class library


Solution

  • is it possible to write all core or data layer code inside different razor class library

    Please check the official document and this tutorial:
    The Razor views, pages, controllers, page models, Razor components, View components, and data models can be built into a Razor class library (RCL). The RCL can be packaged and reused. Applications can include the RCL and override the views and pages it contains. When a view, partial view, or Razor Page is found in both the web app and the RCL, the Razor markup (.cshtml file) in the web app takes precedence.

    So, you can write the Data layer code or logic in the Razor class library. But in my opinion, I suggest you could put the data layer code in the regular class library, then you could reuse them in other projects.