Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

[Feature] Inject TagHelperComponents at runtime #6282

Closed

Description

@sebastienros

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 ITagHelperComponentManager for devs to resolve it and add new ITagHelperComponent instances.
  • ITagHelperComponentManager could be a DI-registered composite of ITagHelperComponent. (need to solve what order it should have compared to other DI-registered ones)
  • Create a ScriptTagHelperComponent and 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 ITagHelperComponentManager in the view
    • Call `tagHelperComponentManager.Add(new ScriptTagHelperComponent("jquery.js"))
  • 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.

Activity

  1. DamianEdwards commented on May 16, 2017

    @DamianEdwards
    Member

    For now, I want to limit this to just the ability to add ITagHelperComponents during request processing, e.g. from a controller or view. I don't want us to add ScriptTagHelperComponent or otherwise as part of this work, that will remain an application concern for now.

    We need to decide whether the ITagHelperComponentManager supports activation of the ITagHelperComponents added (via the container) or not. In many other places in the framework, extension points like this support activating the added types from the container, e.g. Tag Helpers, View Components, Controllers, etc. I'm not sure if we support activation of other things currently like Filters, Formatters, etc. If we do want to support that, we'll need methods on ITagHelperComponentManager that support it, e.g. ITagHelperComponentManager.Add<FooTagHelperComponent>().

  2. rynowak commented on May 16, 2017

    @rynowak
    Contributor

    Do we have a killer scenario lined up for this yet? Maybe we should build that and see what falls out.

  3. added this to the 2.0.0-preview2 milestone on May 18, 2017
  4. added a commit that references this issue on May 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions