0

I want to create a solution that consists of several web .NET Core(Razor) projects, and one of them has the role of startup, and the main settings are done in that project. For example, suppose the solution consists of the following web projects:

AccountingWeb
inventoryWeb
CRMWeb
ProductionWeb
HumanResourceWeb
Mainweb

and the main website of the startup project. If, for example, the following path is entered in the browser. The main web redirects it to the accounting project (controller, model and view).

/Accounting/Article/Index

I made this structure but it seems that the views folder of sub projects should be in the main project. Has anyone worked with this build? Thank you for sending me your feedback

1 Answers1

1

If you want one of our "projects" to be considered as a web project it has to be a web server. In .net-core web servers created like this: var builder = WebApplication.CreateBuilder(args);. Then you can add Startup.cs and configure each server independently. But it's going to be hard to achieve redirecting functionality you mentioned and you also would have to solve problems with deploying of such services and managing them.

As I understood from your question, you really want only one of your projects to be a web server (MainWeb). Then, rest of your projects could be just class libraries containing controllers in them. You can register controllers to MainWeb by following this answer.

What is usually is a general practice is that you have one Web Server containing all controllers (if you want you can move them in different namespaces). In each controller you call appropriate service (or command, or request executor, depending which pattern do you use). This services could be stored in different class libraries. For example:

Mainweb.csproj (web server)
  - Controllers
  - - Accounting
  - - - AccountingController.cs
  Startup.cs
  Program.cs
AccountingProcessor.csproj (class library)
 - RequestProcessors
 - - AccountingRequestProcessor.cs

Here, MainWeb references AccountingProcessor. Accounting processor does the logic for all accounting requests.

If you don't have any other restrictions which require you to have these projects to be a web, I would choose this option.

  • I have already done the same. But I somehow want to implement the microservice with the solution. Each independent web project does its work and the only dependence of each project is on the domain for services. The main project should also depend on all webs to manage requests. – EbrahimFarahmand Mar 02 '23 at 06:23
  • Implementing microservices is a hard task and managing them even harder. There are some options you can choose from: implement everything yourself (bad idea) or use some orchestration like Kubernates or Service Fabric. Here is a tutorial how to do it with Kubernates https://learn.microsoft.com/en-us/training/paths/create-microservices-with-dotnet/ You can also check https://learn.microsoft.com/en-us/azure/service-fabric/ – vshishkarov Mar 02 '23 at 10:35