Best approach multidomain .NET Core application

.net-core dbcontext entity-framework-core razor


I'm building multiple websites that share some classes, methods and information. What is the best way to do this?

The application is written in core 2.2 using razor pages. The plan is to share some code with multiple websites/domains, like:

- components
- models
- some pages
- partials
- custom tag helpers 
- dbcontext

But every domain has also it's own sources:

- styling (sccss)
- (external) libraries (like javascript plugins)
- some additional domain-specific pages
- appsettings.json
- _layout.cshtml

The database (EF Core - DB context) is shared, as well as a bunch of static files (images). But we need to set cookies and session data per domain/website.

It's not necessary for now, but maybe we want to share a login-session through multiple domains in the future.

It would be nice if we can update just a single domain, using a shared set of dll's, without the need to rebuild all code.

1/10/2019 12:22:41 PM

Accepted Answer

Some hours of research and trial and error, brought me a partial solution. First of all I splitted up the project in a Razor Class Library (RCL) with the shared pages/models/classes/tag helpers/extensions/styles etc. Even the DbContext is in it :). And the other project contains my 'domain-specific overrides'. It works pretty good.


  1. To create a my RCL, I used this: Creat reusable UI (of course...)

  2. To register the interfaces and DbContext, I used this: How to inject services...

  3. And to embed 'static' files (js/css) I used this: Including Static Resources

Last things to do is register the dll's of my shared RCL on the webserver and upload the different domain-projects to the domains. Haven't done that yet, but it seems to be quite easy.

This solution fulfills my expectations, but maybe it's not the best way. Please feel free to post other solutions!

1/10/2019 12:54:58 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow