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

Tag Helpers: Modify TagHelper creation to activate ViewContext properties instead of inheriting from an interface. #1258

Closed
NTaylorMullen opened this issue Oct 7, 2014 · 3 comments

Comments

@NTaylorMullen
Copy link
Member

Right now TagHelpers can retrieve the RazorPage's ViewContext by implementing ICanHasViewContext, after talks with @yishaigalatzer we've decided that we don't want this interface to be publicly facing and that we can provide the ViewContext to the TagHelper in a better format.

New way:

class DivTagHelper : TagHelper
{
    [Activate]
    public ViewContext ViewContext { get; set; }
}

Note: Once aspnet/Razor/issues/182 is implemented we can decide if we want to make [Activate] take on the same behavior or if we want to make users be explicit on the [NotBound] attribute.

@NTaylorMullen NTaylorMullen self-assigned this Oct 7, 2014
@NTaylorMullen NTaylorMullen added this to the 6.0.0-beta1 milestone Oct 7, 2014
@yishaigalatzer
Copy link
Contributor

go for it

NTaylorMullen added a commit that referenced this issue Oct 7, 2014
- The TagHelperActivator enables dependency injection via properties and allows access to the ViewContext.
- This replaces the ICanHasViewContext mechanism that we had in place before.
- Added tests and fixed up existing to work with new format for providing ViewContext.

#1258
@dougbu
Copy link
Member

dougbu commented Oct 7, 2014

@NTaylorMullen and @yishaigalatzer could you please clarify this issue?
activators in the system other than DefaultControllerActivator (DefaultViewComponentActivator, RazorPageActivator and the DefaultTagHelperActivator proposed in #1259) all make use of ICanHasViewContext. this is required to handle properties that themselves require ViewContext and means ICanHasViewContext remains public-facing.
so how does fixing this issue address the first part of the excerpt below and what does "better" mean?

we've decided that we don't want this interface to be publicly facing and that we can provide the ViewContext to the TagHelper in a better format

separately tag helpers are already instantiated using ITypeActivator. so we already have a mechanism to give them any service.
note I can see some potential advantages to using [Activate] once [NotBound] exists (or the opposite -- Razor not binding properties by default). for example it allows tag helpers to usefully contain properties that implement ICanHasViewContext. but I'm not sure why we'd address that for Beta.

NTaylorMullen added a commit that referenced this issue Oct 8, 2014
- The TagHelperActivator enables dependency injection via properties and allows access to the ViewContext.
- This replaces the ICanHasViewContext mechanism that we had in place before.
- Added tests and fixed up existing to work with new format for providing ViewContext.

#1258
@NTaylorMullen
Copy link
Member Author

3dff1ca

NTaylorMullen added a commit that referenced this issue Oct 8, 2014
- The TagHelperActivator enables dependency injection via properties and allows access to the ViewContext.
- This replaces the ICanHasViewContext mechanism that we had in place before.
- Added tests and fixed up existing to work with new format for providing ViewContext.

#1258
NTaylorMullen added a commit that referenced this issue Oct 9, 2014
- The TagHelperActivator enables dependency injection via properties and allows access to the ViewContext.
- This replaces the ICanHasViewContext mechanism that we had in place before.
- Added tests and fixed up existing to work with new format for providing ViewContext.

#1258
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

3 participants