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

Add TagHelperContext.Items bag to enable passing values between related tag helpers #238

Closed
DamianEdwards opened this issue Nov 22, 2014 · 5 comments

Comments

@DamianEdwards
Copy link
Member

Add a new property public IDictionary<string, object> Items { get; } to the TagHelperContext class to facilitate the passing of arbitrary items between Tag Helpers running on the same element.

e.g.

[HtmlElementName("my-tag")]
public class MyTagHelper : TagHelper {
    public override void Process(TagHelperContext context, TagHelperOutput output) {
        context.Items["message"] = "This came from the MyTagHelper class!";
    }
}

[HtmlElementName("my-tag")]
public class MyOtherTagHelper : TagHelper {
    public override void Process(TagHelperContext context, TagHelperOutput output) {
        var message = context.Items["message"];
    }
}
@DamianEdwards DamianEdwards added this to the 4.0.0-rc1 milestone Nov 22, 2014
@yishaigalatzer yishaigalatzer modified the milestones: 4.0.0-rc1, 4.0.0-beta3 Jan 15, 2015
@NTaylorMullen NTaylorMullen changed the title Tag Helpers: Add TagHelperContext.Items bag to enable passing values between tag helpers and content Add TagHelperContext.Items bag to enable passing values between tag helpers and content Jan 23, 2015
@NTaylorMullen
Copy link
Member

I don't feel like a single bag to communicate between multiple TagHelpers on the same elment has a whole lot of value and doesn't help solve the major problem of communicating between child => parent and vice versa.

Ultimately it will be less common for TagHelper authors to write multiple TagHelpers that communicate among each other on the same element which is why this item should probably be re-thought to provide greater value.

@dougbu
Copy link
Member

dougbu commented Jan 27, 2015

in an offline discussion, thought we ended with agreement some of the existing property bags (FormContext.FormData, ViewContext.ViewData, likely a few others) had reasonable semantics but not quite the correct scope. this led us to a proposed design where public IDictionary<string, object> Items { get; } is backed by a CopyOnWriteDictionary and each TagHelperContext would initialize that dictionary to its parent's dictionary.

this design provides

  • communication of arbitrary information between tag helpers targeting the same element (no harm though likely not a primary scenario, agreed)
  • communication of arbitrary information between tag helpers and any tag helper nested within
  • worry-free cleanup of per-helper content -- parent and sibling scopes never see a tag helper's changes to its Items content
  • communication of arbitrary information from nested tag helpers back to their parent; all that's required is the parent creating its (well-known) Items entry before executing its childen

@NTaylorMullen
Copy link
Member

The way this item is worded leads me to believe the Items bag is only accessible to TagHelpers running on the same element. If that Items bag is communicated down scope-wise via CopyOnWriteDictionary then I'm 100% on board.

@DamianEdwards
Copy link
Member Author

👍

-----Original Message-----
From: "N. Taylor Mullen" [email protected]
Sent: ‎1/‎27/‎2015 11:19 AM
To: "aspnet/Razor" [email protected]
Cc: "Damian Edwards" [email protected]
Subject: Re: [Razor] Add TagHelperContext.Items bag to enable passing valuesbetween tag helpers and content (#238)

The way this item is worded leads me to believe the Items bag is only accessible to TagHelpers running on the same element. If that Items bag is communicated down scope-wise via CopyOnWriteDictionary then I'm 100% on board.

Reply to this email directly or view it on GitHub.=

@DamianEdwards DamianEdwards changed the title Add TagHelperContext.Items bag to enable passing values between tag helpers and content Add TagHelperContext.Items bag to enable passing values between related tag helpers Jan 29, 2015
NTaylorMullen added a commit that referenced this issue Feb 13, 2015
- Added an extra parameter to the TagHelperScopeManager so when it creates the TagHelperExecutionContext it can retrieve the parent execution context in order to create the Items bag that eventually exists on the TagHelperContext.
- Add a an Item properties on TagHelperExecutionContext to propagate to the TagHelperContext.
- Updated code generation to pass the parent TagHelperExecutionContext into the TagHelperScopeManager.

#238
NTaylorMullen added a commit that referenced this issue Feb 17, 2015
- Added an extra parameter to the TagHelperScopeManager so when it creates the TagHelperExecutionContext it can retrieve the parent execution context in order to create the Items bag that eventually exists on the TagHelperContext.
- Add a an Item properties on TagHelperExecutionContext to propagate to the TagHelperContext.
- Updated code generation to pass the parent TagHelperExecutionContext into the TagHelperScopeManager.

#238
NTaylorMullen added a commit that referenced this issue Feb 17, 2015
- Updated code generation tests to showcase new code generation behavior for building a scope with the parent TagHelperExecutionContext.
- Added TagHelperExecutionContext tests to ensure that the Items bag is correctly wrapped.
- Updated existing unit tests to abide by the new constructor format of TagHelperScopeManager, TagHelperContext and TagHelperExecutionContext

#238
NTaylorMullen added a commit that referenced this issue Feb 18, 2015
- Added an extra parameter to the TagHelperScopeManager so when it creates the TagHelperExecutionContext it can retrieve the parent execution context in order to create the Items bag that eventually exists on the TagHelperContext.
- Add a an Item properties on TagHelperExecutionContext to propagate to the TagHelperContext.
- Updated code generation to pass the parent TagHelperExecutionContext into the TagHelperScopeManager.

#238
NTaylorMullen added a commit that referenced this issue Feb 18, 2015
- Updated code generation tests to showcase new code generation behavior for building a scope with the parent TagHelperExecutionContext.
- Added TagHelperExecutionContext tests to ensure that the Items bag is correctly wrapped.
- Updated existing unit tests to abide by the new constructor format of TagHelperScopeManager, TagHelperContext and TagHelperExecutionContext

#238
NTaylorMullen added a commit that referenced this issue Feb 19, 2015
- Added an extra parameter to the TagHelperScopeManager so when it creates the TagHelperExecutionContext it can retrieve the parent execution context in order to create the Items bag that eventually exists on the TagHelperContext.
- Add a an Item properties on TagHelperExecutionContext to propagate to the TagHelperContext.
- Updated code generation to pass the parent TagHelperExecutionContext into the TagHelperScopeManager.

#238
NTaylorMullen added a commit that referenced this issue Feb 19, 2015
- Updated code generation tests to showcase new code generation behavior for building a scope with the parent TagHelperExecutionContext.
- Added TagHelperExecutionContext tests to ensure that the Items bag is correctly wrapped.
- Updated existing unit tests to abide by the new constructor format of TagHelperScopeManager, TagHelperContext and TagHelperExecutionContext

#238
NTaylorMullen added a commit that referenced this issue Feb 23, 2015
- Add a an Item properties on TagHelperExecutionContext to propagate to the TagHelperContext.
- Updated TagHelperScopeManager to create CopyOnWriteDictionary item bags for created TagHelperExecutionContexts.

#238
NTaylorMullen added a commit that referenced this issue Feb 23, 2015
- Added TagHelperScopeManager tests to ensure that the Items bag is correctly wrapped.
- Added test to TagHelperExecutionContext to make sure items bags are properly propogated.
- Updated existing unit tests to abide by the new constructor format of TagHelperScopeManager, TagHelperContext and TagHelperExecutionContext

#238
NTaylorMullen added a commit that referenced this issue Feb 23, 2015
- Add a an Item properties on TagHelperExecutionContext to propagate to the TagHelperContext.
- Updated TagHelperScopeManager to create CopyOnWriteDictionary item bags for created TagHelperExecutionContexts.

#238
NTaylorMullen added a commit that referenced this issue Feb 23, 2015
- Added TagHelperScopeManager tests to ensure that the Items bag is correctly wrapped.
- Added test to TagHelperExecutionContext to make sure items bags are properly propogated.
- Updated existing unit tests to abide by the new constructor format of TagHelperScopeManager, TagHelperContext and TagHelperExecutionContext

#238
NTaylorMullen added a commit to aspnet/Mvc that referenced this issue Feb 23, 2015
- Updated tests to create TagHelperContext correctly.
@NTaylorMullen
Copy link
Member

b95e73e
677df32

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants