Multiple Sites / Razor Class Libraries

2024/06/06 1:53 AM

I was looking at the documentation, specifically this page about managing multiple sites and I'm having issues getting it to work correctly.

I created the RCL and added my /Features folder with a folder called /Home under it and added my MVC files in it. I added a reference in the main project to the RCL but two things I'm noticing are that my controller file in the RCL is now missing references to Kentico objects (and I can't add a reference to the RCL because it will cause cyclical references) and also no matter what I've tried to do it won't read my MVC files in the RCL when running Kentico. If I have the same files present in both projects, I do get errors about clashing files but once I remove the main project's files it just gives the "The View '' was not found" errors and it won't hit a breakpoint in my controller either.

I'm guessing there is something simple that I'm missing but the documentation doesn't go into a whole lot of detail.

Also, I'm curious if we should leave the generated class files that Kentico makes in the Kentico app project or move those also to the RCL for the separate website?


Environment

  • Xperience by Kentico version: [29.1.2]
  • .NET version: [8]
  • Deployment environment: localhost

Answers

2024/06/06 9:30 PM

I solved it!

For those wondering, here is what was happening:

When I added the RCL, it did not save by default into the same folder as my existing Kentico project and created an altogether separate project and folder for the RCL, which causes all kinds of reference issues and doesn't work in the same way as when the folder is within the existing solution.

Once I created a new RCL inside the existsing Kentico solution / folder, everything worked as expected.

2024/06/10 6:18 PM
Answer

@Mike, first a few questions before diagnosing your problems.

  1. Why do you need to separate your presentation code into 1 or more libraries?

    A multi-project architecture will add complexity to your solution and you should adopt it only if it helps manage complexity in other areas.

  2. If you do need a multi-project architecture, what do you want to isolate and what do you want to share?

    You will need to decide with each presentational component and generated class, which project it should assigned to and how to organize your dependencies.

If you need a multi-project solution architecture to isolate your website channel presentation logic, then you'd likely end up with something like this:

Multi-project Xperience by Kentico architecture

Your website channel libraries will contain Controller, View, View model, View component, and content type classes that are used by specific website channels.

Your core library will contain the types of code that are used across all website channels.

When using those separate library projects in your ASP.NET Core project, you'll need to make sure you add the application parts to make them discoverable by ASP.NET Core, and enable class discovery for any Xperience code in each project.

2024/06/10 6:33 PM

The why: We have a single instance of Kentico that will host 4-5 distinct website channels in it. For clarity in managing this, I assume we would want to separate out the codebase for each website.

The what: There isn't much that would be shared amongst them all, although we will be mindful of this as we build the site and if there are things that can be shared we will plan accordingly. For the most part, though, the sites will be independent of each other.

Would you suggest another way of structuring this besides what the doucmentation described for multiple site configurations?

If not though, and if I was headed in the right direction, I think I need to look more into the last two things you mentioned (application parts and class discovery) because I started down that path but wasn't sure if it was what I needed to do.

I appreciate your helpful insights though!

To answer this question, you have to login first.