2

I'm looking for a way to write plugin-based Angular application using Visual Studio and ASP .NET Core SPA project template.

I'm newbie to Angular, and I still reading the docs.
It looks like router + lazy loaded modules is what I need. Main application doesn't need to refer these modules directly, and only appropriate routes configuration is required.

Also, some web search shows, that router can be reconfigured dynamically. E.g. main app calls my API, which returns available routes, built from plugins list somehow.

The question is how lazy loaded angular modules will fit VS project system. All Angular + VS samples I found are using single VS project.

But I need something similar to C#/.NET. For example, typical plugin-based C# app consists of:

  • common project with plugin contract IPlugin;
  • host project with some PluginHost, which knows about IPlugin and can load its implementations;
  • a number of projects with IPlugin implementations.

That is, someone can develop his own implementation, copy resulting assembly into app directory, re-run app, and get new functional.

Is there any way to achieve this using Angular and Visual Studio (not VS Code)?

Dennis
  • 37,026
  • 10
  • 82
  • 150
  • Curious - where did you read that you can reconfigure router dynamically? It is possible, yes, but it's a bit hacky, to the best of my knowledge. – Zlatko Dec 04 '18 at 12:21
  • @Zlatko: one of the links I found: https://stackoverflow.com/a/42928292/580053 Honestly, I did't check how it works. – Dennis Dec 04 '18 at 12:26
  • 1
    Yes, well, this should work, but bundling it all will require some attention. As I've said, it's not a trivial thing. What I would do is make certain that I have an `e2e` test for each of the lazy modules I expect to be loaded during the app runtime, to make sure all my lazy-module bundles are there. – Zlatko Dec 04 '18 at 12:28

1 Answers1

3

You might want to design your common stuff and your implementations as angular libraries (ng generate library).

There are a few ways to pack this together - from Monorepo (which you apparently do not want to use) to building them all as separate libraries, but the main thing is still that you'd just import these libraries from npm as any other package (or as Angular itself) and use their exported APIs.

There are a few resources on this, e.g. this, this or this.

Now, how to proceed further than this, maybe read up a bit more and then post more specific questions.

Zlatko
  • 18,936
  • 14
  • 70
  • 123
  • 1
    I've found interesting issue: https://github.com/angular/angular-cli/issues/6373 Looks like people want to do the same things (however, not related to VS), and this still not possible. – Dennis Dec 06 '18 at 09:42