-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Conversation
} | ||
|
||
if (loggerFactory == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerFactory)); | ||
} | ||
|
||
_components = components; | ||
_components = new List<ITagHelperComponent>(manager.Components.OrderBy(p => p.Order)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manager.Components.OrderBy(p => p.Order).ToArray()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why ToArray()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ToList()
operation is more readable.
Then there is no need for a list, hence ToArray
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I thought this was the provider itself. This is the taghelper.
|
||
namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers | ||
{ | ||
public interface ITagHelperComponentManager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will need comments.
public void Add(ITagHelperComponent tagHelperComponent) | ||
{ | ||
_tagHelperComponents.Add(tagHelperComponent); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not IList<>
for the components? Is is not supported to remove components?
I can see two sensible ways that ITagHelperManager
deals with ordering in a consistent way.
-
Expose
IList<>
for the components. The components from DI are always put in order for you. Callers can add or insert a component wherever they want, reorder the list, remove stuff, etc. -
Expose
IEnumerable<>
orICollection<>
. Calling add should find the right place in the list for the new component based on its order and insert it. UseICollection<>
if you want to support removing things orIEnumerable<>
if you don't.
@sebastienros @rynowak Updated |
{ | ||
/// <summary> | ||
/// Contract used to manage <see cref="ITagHelperComponent"/>s. | ||
/// </summary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't super useful, what can you do with it?
using System.Collections.ObjectModel; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a more secretive namespace like .Internal
, there's no need for anyone to interact with this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from me after addressing small comments. Get a
from 🇫🇷 as well
} | ||
|
||
/// <inheritdoc /> | ||
public ICollection<ITagHelperComponent> Components { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Suggest
IList<T>
sinceICollection<T>
is a loser interface. - remove the
private set;
bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, missed @rynowak's comment about the chosen collection type. We obviously want to Add()
so IEnumerable<T>
is out.
The main differences between ICollection<T>
and IList<T>
are odd gaps in ICollection<T>
e.g. no RemoveAt()
. But, both support Remove()
and I lean toward IList<T>
here.
@@ -15,7 +15,7 @@ public override Task ProcessAsync(TagHelperContext context, TagHelperOutput outp | |||
{ | |||
if (string.Equals(context.TagName, "body", StringComparison.Ordinal) && output.Attributes.ContainsName("inject")) | |||
{ | |||
output.PostContent.AppendHtml("<script>'This was injected!!'</script>"); | |||
output.PostContent.AppendHtml("<script>'This was injected!!'</script>\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not add Windows-specific line endings. My preference is to leave this unchanged because this changes the baselines for no reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for TestHeadTagHelperComponent
<script>'This was injected!!'</script> | ||
</body> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusing that this and RazorWebSite.TagHelperComponent.Head.html changed at all. As mentioned later, revert the .cshtml changes.
{ | ||
new CallbackTagHelperComponent( | ||
new CallbackTagHelperComponent( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restore the leading space.
} | ||
|
||
if (loggerFactory == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerFactory)); | ||
} | ||
|
||
_components = components; | ||
_components = manager.Components.OrderBy(p => p.Order).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment mentioning this ordering must be done after the manager is created (otherwise controller-added components won't be positioned correctly).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
67e1e9d
to
8f343be
Compare
@dougbu Updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting close. Sorry if I missed a couple of things in my previous read-through.
@@ -18,10 +18,11 @@ public class BodyTagHelper : TagHelperComponentTagHelper | |||
/// <summary> | |||
/// Creates a new <see cref="BodyTagHelper"/>. | |||
/// </summary> | |||
/// <param name="components">The list of <see cref="ITagHelperComponent"/>.</param> | |||
/// <param name="manager">The <see cref="ITagHelperComponentManager"/> which contains the list |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"contains the list" -> "contains the collection" throughout this PR. (There's a few left after your comment updates.)
{ | ||
/// <summary> | ||
/// An implementation of this interface provides the collection of <see cref="ITagHelperComponent"/>s | ||
/// that will be used by the <see cref="TagHelperComponentTagHelper"/>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor but <see cref="TagHelperComponentTagHelper"/>s
is better than the <see cref="TagHelperComponentTagHelper"/>
because there isn't just one <see cref="TagHelperComponentTagHelper"/>
.
} | ||
|
||
if (loggerFactory == null) | ||
{ | ||
throw new ArgumentNullException(nameof(loggerFactory)); | ||
} | ||
|
||
_components = components; | ||
_components = manager.Components.OrderBy(p => p.Order).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx
|
||
public void Init(TagHelperContext context) | ||
{ | ||
context.Items["Key2"] = "Value2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this Items
entry used for? Same for the similar code in later test components.
|
||
private class TestAddTagHelperComponent : ITagHelperComponent | ||
{ | ||
public int Order => 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest making this settable and including it in what's added to PostContent
. Then, can test that controller-added components are processed in the correct order.
<ProjectReference Include="..\Microsoft.AspNetCore.Mvc.TestConfiguration\Microsoft.AspNetCore.Mvc.TestConfiguration.csproj" /> | ||
|
||
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="$(AspNetCoreVersion)" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these dependencies; Microsoft.AspNetCore.Mvc brings them in.
|
||
namespace RazorWebSite | ||
{ | ||
public class TestViewTagHelperComponent : ITagHelperComponent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure why we've got multiple almost-identical components in this web site. Couldn't the bits that differ e.g. the appended content be passed into the constructor or (hmm, Order
) set?
@dougbu Updated |
|
||
// Act | ||
await testTagHelperComponentTagHelper.ProcessAsync(tagHelperContext, output); | ||
|
||
// Assert | ||
Assert.Equal("Processed", output.PostContent.GetContent()); | ||
Assert.Equal("Processed0Processed1Processed2", output.PostContent.GetContent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
b1cef98
to
a92f25c
Compare
Addresses #6282
cc @sebastienros