This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back support for AddTagHelpersAsServices
This doesn't go through the Razor tag helper discovery pipeline because this can really only ever work for ITagHelper based taghelpers. So there's really no point in reusing that logic, which would be hard anyway.
- Loading branch information
Showing
6 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Microsoft.AspNetCore.Mvc.Razor/TagHelpers/TagHelperFeatureProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Microsoft.AspNetCore.Mvc.ApplicationParts; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers | ||
{ | ||
public class TagHelperFeatureProvider : IApplicationFeatureProvider<TagHelperFeature> | ||
{ | ||
public void PopulateFeature(IEnumerable<ApplicationPart> parts, TagHelperFeature feature) | ||
{ | ||
foreach (var part in parts) | ||
{ | ||
if (IncludePart(part) && part is IApplicationPartTypeProvider typeProvider) | ||
{ | ||
foreach (var type in typeProvider.Types) | ||
{ | ||
var typeInfo = type.GetTypeInfo(); | ||
if (IncludeType(typeInfo) && !feature.TagHelpers.Contains(typeInfo)) | ||
{ | ||
feature.TagHelpers.Add(typeInfo); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected virtual bool IncludePart(ApplicationPart part) => true; | ||
|
||
protected virtual bool IncludeType(TypeInfo type) | ||
{ | ||
// We don't need to check visibility here, that's handled by the type provider. | ||
return | ||
typeof(ITagHelper).GetTypeInfo().IsAssignableFrom(type) && | ||
!type.IsAbstract && | ||
!type.IsGenericType; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters