C# 如何使用Unity将FilteredItemsNodeVisibilityProvider注入SiteMapNodeVisibilityProviderStrategy

C# 如何使用Unity将FilteredItemsNodeVisibilityProvider注入SiteMapNodeVisibilityProviderStrategy,c#,asp.net-mvc,unity-container,mvcsitemapprovider,C#,Asp.net Mvc,Unity Container,Mvcsitemapprovider,我不知道如何使用Unity设置默认可见性提供程序。我使用了内部DI容器,它可以工作,但与外部所有节点都会显示出来 在web.config中 <add key="MvcSiteMapProvider_UseExternalDIContainer" value="true"/> 根据,使用解析默认提供程序 这是Unity的自动注册码。如果您在另一个程序集中有ISiteMapNodeVisibilityProvider实现,则可以在此处添加该程序集名称 var allAssemblies

我不知道如何使用Unity设置默认可见性提供程序。我使用了内部DI容器,它可以工作,但与外部所有节点都会显示出来

web.config中

<add key="MvcSiteMapProvider_UseExternalDIContainer" value="true"/>
根据,使用解析默认提供程序

这是Unity的自动注册码。如果您在另一个程序集中有
ISiteMapNodeVisibilityProvider
实现,则可以在此处添加该程序集名称

var allAssemblies = new Assembly[] { currentAssembly, siteMapProviderAssembly };
var excludeTypes = new Type[] { 
    // Use this array to add types you wish to explicitly exclude from convention-based  
    // auto-registration. By default all types that either match I[TypeName] = [TypeName] or 
    // I[TypeName] = [TypeName]Adapter will be automatically wired up as long as they don't 
    // have the [ExcludeFromAutoRegistrationAttribute].
    //
    // If you want to override a type that follows the convention, you should add the name 
    // of either the implementation name or the interface that it inherits to this list and 
    // add your manual registration code below. This will prevent duplicate registrations 
    // of the types from occurring. 

    // Example:
    // typeof(SiteMap),
    // typeof(SiteMapNodeVisibilityProviderStrategy)
};
var multipleImplementationTypes = new Type[]  { 
    typeof(ISiteMapNodeUrlResolver), 
    typeof(ISiteMapNodeVisibilityProvider), // <- These are automatically registered by convention
    typeof(IDynamicNodeProvider) 
};

// ...

// Multiple implementations of strategy based extension points (and not decorated with [ExcludeFromAutoRegistrationAttribute]).
CommonConventions.RegisterAllImplementationsOfInterface(
    (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, implementationType.Name, new ContainerControlledLifetimeManager()),
    multipleImplementationTypes,
    allAssemblies,
    excludeTypes,
    string.Empty);
var allAssemblies=新程序集[]{currentAssembly,siteMapProviderAssembly};
var excludeTypes=新类型[]{
//使用此数组可添加要从基于约定的规则中显式排除的类型
//自动注册。默认情况下,所有匹配I[TypeName]=[TypeName]或
//I[TypeName]=[TypeName]适配器将自动连接,只要它们不连接
//拥有[ExcludeFromAutoRegistrationAttribute]。
//
//如果要重写遵循约定的类型,则应添加名称
//实现名称或它继承到此列表的接口的
//在下面添加手动注册码。这将防止重复注册
//防止发生的类型。
//例如:
//类型(网站地图),
//类型(SiteMapNodeVisibilityProviderStrategy)
};
var multipleImplementTypes=新类型[]{
类型(IsItemaNodeUrlResolver),
typeof(ISiteMapNodeVisibilityProvider),//this.Container.RegisterType(interfaceType,implementationType,implementationType.Name,new ContainerControlled LifetimeManager()),
多种实施类型,
诸位,
排除类型,
字符串(空);

非常感谢!太棒了!
this.Container.RegisterType<ISiteMapNodeVisibilityProviderStrategy, SiteMapNodeVisibilityProviderStrategy>(new InjectionConstructor(
    new ResolvedArrayParameter<ISiteMapNodeVisibilityProvider>(this.Container.ResolveAll<ISiteMapNodeVisibilityProvider>().ToArray()),
    new InjectionParameter<string>("MvcSiteMapProvider.FilteredSiteMapNodeVisibilityProvider, MvcSiteMapProvider")
));
// Visibility Providers
this.Container.RegisterType<ISiteMapNodeVisibilityProvider, FilteredSiteMapNodeVisibilityProvider>("defaultProvider");
this.Container.RegisterType<ISiteMapNodeVisibilityProvider, TrimEmptyGroupingNodesVisibilityProvider>("trimVisibilityProvider");
var allAssemblies = new Assembly[] { currentAssembly, siteMapProviderAssembly };
var excludeTypes = new Type[] { 
    // Use this array to add types you wish to explicitly exclude from convention-based  
    // auto-registration. By default all types that either match I[TypeName] = [TypeName] or 
    // I[TypeName] = [TypeName]Adapter will be automatically wired up as long as they don't 
    // have the [ExcludeFromAutoRegistrationAttribute].
    //
    // If you want to override a type that follows the convention, you should add the name 
    // of either the implementation name or the interface that it inherits to this list and 
    // add your manual registration code below. This will prevent duplicate registrations 
    // of the types from occurring. 

    // Example:
    // typeof(SiteMap),
    // typeof(SiteMapNodeVisibilityProviderStrategy)
};
var multipleImplementationTypes = new Type[]  { 
    typeof(ISiteMapNodeUrlResolver), 
    typeof(ISiteMapNodeVisibilityProvider), // <- These are automatically registered by convention
    typeof(IDynamicNodeProvider) 
};

// ...

// Multiple implementations of strategy based extension points (and not decorated with [ExcludeFromAutoRegistrationAttribute]).
CommonConventions.RegisterAllImplementationsOfInterface(
    (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, implementationType.Name, new ContainerControlledLifetimeManager()),
    multipleImplementationTypes,
    allAssemblies,
    excludeTypes,
    string.Empty);