This repository was archived by the owner on Dec 14, 2018. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
[Feature] Inject TagHelperComponents at runtime #6282
Copy link
Copy link
Closed
Description
Goal:
As a developer, be able to inject a script dynamically. For example from a controller, a filter, or a service.
Design suggestion:
- Create a
ITagHelperComponentManagerfor devs to resolve it and add newITagHelperComponentinstances. ITagHelperComponentManagercould be a DI-registered composite ofITagHelperComponent. (need to solve what order it should have compared to other DI-registered ones)- Create a
ScriptTagHelperComponentand other types of resources that can be used directly from code.
Usages examples:
- From a view or a view component, we can register custom scripts
- Inject the
ITagHelperComponentManagerin the view - Call `tagHelperComponentManager.Add(new ScriptTagHelperComponent("jquery.js"))
- Inject the
- From a filter or a controller, inject a script based on some condition.
Other ideas:
We could also provide some methods on the manager, or extension methods, to prevent duplicate scripts. Like TryAddScript(string), TryAddStylesheet(string). These could also be available as Tag Helpers.
A future need will be to provide another service to handle a sort of DI container for client assets (dependencies, orders, cdn, hash, async, ...) that would ultimately register components on this ITagHelperComponentManager.