我正在尝试将以下StructureMap代码从MvcSiteMapProvider官方文档移植到温莎城堡。
// 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))));
我没有正确移植代码吗?
答案 0 :(得分:1)
我没有为OnComponentCollection
使用正确的方法重载。 CompositeSiteMapNodeVisibilityProvider
的构造函数有一个名为siteMapNodeVisibilityProviders
的参数。
.DependsOn(Dependency.OnComponentCollection(
"siteMapNodeVisibilityProviders",
typeof(FilteredSiteMapNodeVisibilityProvider),
typeof(TrimEmptyGroupingNodesVisibilityProvider),
typeof(PropertyTypeGlobalNodeVisibilityProvider)))