如何一次使用多个全局 ISiteMapNodeVisibilityProvider 实现?
How to use multiple global ISiteMapNodeVisibilityProvider implementations at a time?
我正在尝试将 MvcSiteMapProvider 官方文档中的以下 StructureMap 代码移植到 Castle Windsor。
// Visibility Providers
// Explicitly set the visibility providers, using CompositeSiteMapNodeVisibilityProvider to combine the AclModuleVisibilityProvider
// with all other ISiteMapNodeVisibilityProvider implementations.
this.For<ISiteMapNodeVisibilityProviderStrategy>().Use<SiteMapNodeVisibilityProviderStrategy>()
.EnumerableOf<ISiteMapNodeVisibilityProvider>().Contains(x =>
{
x.Type<CompositeSiteMapNodeVisibilityProvider>()
.Ctor<string>("instanceName").Is("filteredAndTrimmedAndCustom")
.EnumerableOf<ISiteMapNodeVisibilityProvider>().Contains(y =>
{
// Note that the visibility providers are executed in
// the order specified here, but execution stops when
// the first visibility provider returns false.
y.Type<FilteredSiteMapNodeVisibilityProvider>();
y.Type<TrimEmptyGroupingNodesVisibilityProvider>();
y.Type<CustomVisibilityProvider>();
});
})
.Ctor<string>("defaultProviderName").Is("filteredAndTrimmedAndCustom");
这是我的温莎城堡代码:
// Visibility Providers
container.Register(
Component.For<ISiteMapNodeVisibilityProvider>()
.Named("filteredAndTrimmedAndCustom")
.ImplementedBy<CompositeSiteMapNodeVisibilityProvider>()
.DependsOn(Dependency.OnValue(
"instanceName",
"filteredAndTrimmedAndCustom"))
.DependsOn(Dependency.OnComponentCollection(
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(CustomVisibilityProvider))));
container.Register(
Component.For<ISiteMapNodeVisibilityProviderStrategy>()
.ImplementedBy<SiteMapNodeVisibilityProviderStrategy>()
.DependsOn(Dependency.OnValue(
"defaultProviderName",
"filteredAndTrimmedAndCustom")));
问题是我所有的 ISiteMapNodeVisibilityProvider
实现都在这段代码之后全局使用。如果我有一个名为 ``ABCVisibilityProvider` 的本地可见性提供程序,它也将在全球范围内使用。此行似乎没有正常工作:
.DependsOn(Dependency.OnComponentCollection(
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(CustomVisibilityProvider))));
我是不是没有正确移植代码?
我没有为 OnComponentCollection
使用正确的方法重载。 CompositeSiteMapNodeVisibilityProvider
的构造函数有一个名为 siteMapNodeVisibilityProviders
.
的参数
.DependsOn(Dependency.OnComponentCollection(
"siteMapNodeVisibilityProviders",
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(PropertyTypeGlobalNodeVisibilityProvider)))
我正在尝试将 MvcSiteMapProvider 官方文档中的以下 StructureMap 代码移植到 Castle Windsor。
// Visibility Providers
// Explicitly set the visibility providers, using CompositeSiteMapNodeVisibilityProvider to combine the AclModuleVisibilityProvider
// with all other ISiteMapNodeVisibilityProvider implementations.
this.For<ISiteMapNodeVisibilityProviderStrategy>().Use<SiteMapNodeVisibilityProviderStrategy>()
.EnumerableOf<ISiteMapNodeVisibilityProvider>().Contains(x =>
{
x.Type<CompositeSiteMapNodeVisibilityProvider>()
.Ctor<string>("instanceName").Is("filteredAndTrimmedAndCustom")
.EnumerableOf<ISiteMapNodeVisibilityProvider>().Contains(y =>
{
// Note that the visibility providers are executed in
// the order specified here, but execution stops when
// the first visibility provider returns false.
y.Type<FilteredSiteMapNodeVisibilityProvider>();
y.Type<TrimEmptyGroupingNodesVisibilityProvider>();
y.Type<CustomVisibilityProvider>();
});
})
.Ctor<string>("defaultProviderName").Is("filteredAndTrimmedAndCustom");
这是我的温莎城堡代码:
// Visibility Providers
container.Register(
Component.For<ISiteMapNodeVisibilityProvider>()
.Named("filteredAndTrimmedAndCustom")
.ImplementedBy<CompositeSiteMapNodeVisibilityProvider>()
.DependsOn(Dependency.OnValue(
"instanceName",
"filteredAndTrimmedAndCustom"))
.DependsOn(Dependency.OnComponentCollection(
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(CustomVisibilityProvider))));
container.Register(
Component.For<ISiteMapNodeVisibilityProviderStrategy>()
.ImplementedBy<SiteMapNodeVisibilityProviderStrategy>()
.DependsOn(Dependency.OnValue(
"defaultProviderName",
"filteredAndTrimmedAndCustom")));
问题是我所有的 ISiteMapNodeVisibilityProvider
实现都在这段代码之后全局使用。如果我有一个名为 ``ABCVisibilityProvider` 的本地可见性提供程序,它也将在全球范围内使用。此行似乎没有正常工作:
.DependsOn(Dependency.OnComponentCollection(
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(CustomVisibilityProvider))));
我是不是没有正确移植代码?
我没有为 OnComponentCollection
使用正确的方法重载。 CompositeSiteMapNodeVisibilityProvider
的构造函数有一个名为 siteMapNodeVisibilityProviders
.
.DependsOn(Dependency.OnComponentCollection(
"siteMapNodeVisibilityProviders",
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(PropertyTypeGlobalNodeVisibilityProvider)))