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

Add support for ViewComponentTagHelpers. #937

Merged
merged 1 commit into from Jan 19, 2017

Conversation

NTaylorMullen
Copy link
Member

  • Hardcoded ViewComponent discovery.
  • Hardcoded ViewComponentTagHelperDescriptor creation.
  • Added test to validate that ViewComponents are discovered and transitioned into TagHelpers properly.
  • Avoided adding a reference to MVC to prevent circular references. This resulted in custom marker attributes to represent ViewComponents. Also made a lot of use of ViewComponent conventions (ending in "ViewComponent").

#932

@@ -19,46 +21,82 @@ public DefaultTagHelperResolver(bool designTime)
public override IReadOnlyList<TagHelperDescriptor> GetTagHelpers(Compilation compilation)
{
var results = new List<TagHelperDescriptor>();
var errors = new ErrorSink();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't flow this error sink out today. It'd probably be valuable to do that to inform tooling on bits that go wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. We need to do a refactor on THD or least evaluate the design. Let's plan on doing this today.

{
try
{
var descriptor = factory.CreateDescriptor(type);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These bits will be replaced by MVC invocations. Didn't feel that it was worth the time to convert each exception clause into an errorSink.OnError call/flow the ErrorSink throughout the factory.

return results;
private static void VisitViewComponents(Compilation compilation, List<TagHelperDescriptor> results, ErrorSink errors)
{
var @interface = compilation.GetTypeByMetadataName(ViewComponentTypes.ViewComponentAttribute);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we no-op if this type isn't defined?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you given any thought to how we'll determine if the user is on MVC >= 1.1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we no-op if this type isn't defined?

If there's no attribute the classes could be defined in a class library using the ViewComponent suffix couldn't they?

Have you given any thought to how we'll determine if the user is on MVC >= 1.1

Great question. Hmm, I could look for public types added in 1.1 to check for its existence. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, depending on the approach for detecting 1.1 MVC maybe nooping would be the right approach

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overall looks good!

return results;
private static void VisitViewComponents(Compilation compilation, List<TagHelperDescriptor> results, ErrorSink errors)
{
var @interface = compilation.GetTypeByMetadataName(ViewComponentTypes.ViewComponentAttribute);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you given any thought to how we'll determine if the user is on MVC >= 1.1

return false;
}

return symbol.Name.EndsWith(ViewComponentTypes.ViewComponentSuffix) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also NonViewComponent attribute to consider, which makes the entire hierarchy not a VC.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh shoot, good catch. I missed that bit.

// Will invoke synchronously. Method must not return void, Task or Task<T>.
if (returnType.SpecialType == SpecialType.System_Void)
{
throw new InvalidOperationException(ViewComponentResources.FormatViewComponent_SyncMethod_ShouldReturnValue(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these the errors the VC would report at runtime when called?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

- Hardcoded `ViewComponent` discovery.
- Hardcoded `ViewComponentTagHelperDescriptor` creation.
- Added test to validate that ViewComponents are discovered and transitioned into TagHelpers properly.
- Avoided adding a reference to MVC to prevent circular references. This resulted in custom marker attributes to represent `ViewComponent`s. Also made a lot of use of `ViewComponent` conventions (ending in "ViewComponent").

#932
@NTaylorMullen NTaylorMullen merged commit 6e64785 into dev Jan 19, 2017
@NTaylorMullen NTaylorMullen deleted the nimullen/vctaghelpers.932 branch January 19, 2017 19:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants