locked
How do I call views from separate asp.net core web apps in a single solution from my host asp.net core app? RRS feed

  • Question

  • User-1045336983 posted

    Hi, There's a new project that I'v been assigned and I want to build it in a modular way. I want to create a single Host web app with each web apps(modules) built around it.

    I am thinking of creating a host web app and add references of module projects. I am thinking of creating the main Index.html in the host app with links to the views from my modules.

    I am not sure how I'll achieve the above, I'v read few articles that suggest making use Assembly class methods to load the dlls of my modules and register them in Asp.core's pipeline by AddApplicationPart method but I am not sure how to proceed after that. How do I call a View that is in Module A from my Host app's views. Also, I am planning to make my modules have Angular/React as their front-end in distant future but the current plan is having modules in asp.net core mvc

    So how should I proceed? And what are the best practices that I should follow?

    Sunday, June 16, 2019 10:43 AM

All replies

  • User475983607 posted

    Angular and React are client side applications that run in a browser and commonly call a REST service like Web API.   Your app will not return a View it will return JSON.

    Given your question, I recommend building a few React demo projects.  This will give you the feel of how client side web applications works.  Once you get this experience you'll drop the "modular" server side design for a modular client side design.

    If you decide on Angular, which is fine, you'll need to come to terms with the fact that Angular is a whole system (a framework) and you'll need to learn the framework before moving forward.  

    Sunday, June 16, 2019 11:11 AM
  • User-1045336983 posted

    Thanks for replying.. But what if the plan is have my modules in pure asp.net core mvc..How do I proceed in this case?
    Sunday, June 16, 2019 11:26 AM
  • User475983607 posted

    Test1233@


    Thanks for replying.. But what if the plan is have my modules in pure asp.net core mvc..How do I proceed in this case?

    You are dropping React and Angular? 

    Take a look at the Orchard CMS source code.  Orchard implements modules.

    https://github.com/OrchardCMS/Orchard

    Do you really need to implement modules?  Generally this is a feature found in software that is installed on many servers.  Are you sure you don't simply need the application to add features to your application? 

    Sunday, June 16, 2019 4:00 PM
  • User585649674 posted

    In .net core, if you create separate application for different modules containing its views, they needs to be hosted as different application. But if you want to bring all modules together, it is a long hacking route like you explained adding the dlls to the main app and register them in core pipeline. Pass the viewname while returning view. It will try to find the view in the shared folder or folder with same name as controller. Hence in modules your views should better be in shared folders.

    One more suggestion is to use the concept of "Areas" in aspnet core MVC. Create areas for separate modules. So you can develop each "Areas" independently by different team, you can have separate branches in Git/ TFS for developing each "Areas". And release into production one "Area" by "Area".

    If you are using angular or react they also have the concept of modules and you need to import modules into your starting module. You can develop modules separately at different time by different team and release into production one by one.

    Monday, June 17, 2019 7:10 AM
  • User-1045336983 posted

    Hi, I am building a modular application. The idea here is to make a Host asp.core web app with multiple Modules(web apps) linked to it. The modules will be Angular/React SPAs. 

    I want my Index view of Host to have links to my Modules's views. I read few articles that suggest me to register my modules(assembly) in host app using AddApplicationPart() which is fine. But how do I proceed after that? How should I call the view or link them in my Index view of Host web app? And is it necessary to load assembly is I am calling SPAs?

    Monday, June 17, 2019 2:42 PM
  • User475983607 posted

    It does not make sense to build an modular MVC project if you are building an SPA as explained in a similar thread.  can you explain the high-level reasoning?

    https://forums.asp.net/t/2156708.aspx?How+do+I+call+views+from+separate+asp+net+core+web+apps+in+a+single+solution+from+my+host+asp+net+core+app+

    Test1233@

    But how do I proceed after that? How should I call the view or link them in my Index view of Host web app?

    Views are not called in MVC.  Actions are called which return Views; in other words HTML.  Are you referring to Angular Views not MVC Views?

    Test1233@

    And is it necessary to load assembly is I am calling SPAs?

    An SPA generally calls a REST URL, Web API action, that returns JSON.  Web API would also host any HTML needed to bootstrap the SPA.  For example, the static file handler.

    Monday, June 17, 2019 3:26 PM
  • User-1045336983 posted
    By views I meant angular binded html from my SPA project.. The basic idea here is to isolate my development in terms of modules in such a way that I can assign one module ex. Module A to a team which would work independently from the team working in Module B.
    Monday, June 17, 2019 4:27 PM
  • User-1045336983 posted
    I want to have a host project where I can register i.e add or remove these module on the go
    Monday, June 17, 2019 4:34 PM
  • User475983607 posted

    By views I meant angular binded html from my SPA project.. The basic idea here is to isolate my development in terms of modules in such a way that I can assign one module ex. Module A to a team which would work independently from the team working in Module B.

    I have very little experience with Angular only playing with it to determine if I wanted to use it.  I settled on React and use it in an existing project where adding a "module" or "component" is the standard fare. Usually REST controllers and DI services are built in tandem or a little before the React UI bits.

    I want to have a host project where I can register i.e add or remove these module on the go

    Frankly, your requirements are not clear.  It seems like you are mixing server and client rendering.  Also you keep mentioning Angular/React.  You'll pick one or the other not both.  If you decide to go with Angular, then you are looking at a significant learning curve because Angular does things the Angular way. 

    The idea here is to make a Host asp.core web app with multiple Modules(web apps) linked to it.

    I do not understand what value this has when designing a REST service.   

    Monday, June 17, 2019 5:50 PM
  • User-1045336983 posted

    Oh thanks mate, cleared a lot of confusion.. I get it now that instead of opting for separate projects, I should look for separate angular modules that will help my cause right?

    I just wanted some isolation hence was asking for a 'modular approach'.

    Anyway I think I can still get this modular approach by creating separate web api projects dedicated for a single angular module and have my angular module service call their respective web api end point. 

    Does this sound feasible to you?

    Monday, June 17, 2019 6:29 PM
  • User475983607 posted

    Test1233@

    Oh thanks mate, cleared a lot of confusion.. I get it now that instead of opting for separate projects, I should look for separate angular modules that will help my cause right?

    I'm not an Angular expert.  But I do know that Angular is an entire framework for building web applications.  I recommend visiting an Angular support forum for Software Development Life Cycle (SDLC) best practice advice.

    Test1233@

    Anyway I think I can still get this modular approach by creating separate web api projects dedicated for a single angular module and have my angular module service call their respective web api end point. 

    Does this sound feasible to you?

    Seems like extra work.  You'll end up with several domains with repeated configurations.  Global updates like security or certificates become a hassle.  What's wrong with one Web API application that uses routing to group like actions/controllers?

    I think the main issue you are facing is coming up with a SDLC that fits your organization.  

    If you really want a modular application then see the Orchard CMS on GIT as mentioned in your other thread. 

    https://forums.asp.net/p/2156708/6266281.aspx?Re+How+do+I+call+views+from+separate+asp+net+core+web+apps+in+a+single+solution+from+my+host+asp+net+core+app+

    Monday, June 17, 2019 6:45 PM
  • User-1045336983 posted
    OrchardCms seems like a third party dependency to me. Creating separate web api projects will provide some sort of Separation of Concerns and am thinking of containerizing these web api projects such as they can b individually tested and run. Following Microservice architecture.
    Tuesday, June 18, 2019 3:22 AM
  • User475983607 posted

    OrchardCms seems like a third party dependency to me.

    Huh?  Orchard has the concept of modules and the source is open.   You can see how it is done in Orchard and borrow the technique.

    Creating separate web api projects will provide some sort of Separation of Concerns and am thinking of containerizing these web api projects such as they can b individually tested and run. Following Microservice architecture.

    Microservice architecture is a fine idea. 

    Tuesday, June 18, 2019 1:03 PM