public void Configure(IExportRegistrationBlock container)
        {
            bool     enableLocalization               = true;
            string   absoluteFileName                 = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            TimeSpan slidingCacheExpiration           = TimeSpan.MinValue;
            bool     includeRootNode                  = true;
            bool     useNestedDynamicNodeRecursion    = false;
            bool     visibilityAffectsDescendants     = true;
            bool     useTitleIfDescriptionNotProvided = true;

#if Demo
            // Settings for MvcMusicStore demo: don't copy into your project
            bool     securityTrimmingEnabled  = true;
            string[] includeAssembliesForScan = new string[] { "Mvc Music Store" };
#else
            bool     securityTrimmingEnabled  = false;
            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };
#endif

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            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)
                typeof(SiteMapNodeUrlResolver)
            };

            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
            // and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => container.Export(implementationType).As(interfaceType).AndSingleton(),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points (and not decorated with [ExcludeFromAutoRegistrationAttribute]).
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => container.Export(implementationType).As(interfaceType).AndSingleton(),
                multipleImplementationTypes,
                allAssemblies,
                new Type[0],
                string.Empty);

            // Registration of internal controllers
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => container.Export(implementationType).As(interfaceType).ExternallyOwned(),
                new Type[] { typeof(IController) },
                new Assembly[] { siteMapProviderAssembly },
                new Type[0],
                string.Empty);

            // Visibility Providers
            container.Export <SiteMapNodeVisibilityProviderStrategy>()
            .As <ISiteMapNodeVisibilityProviderStrategy>()
            .WithCtorParam(() => string.Empty).Named("defaultProviderName");

            // Pass in the global controllerBuilder reference
            container.ExportInstance((scope, context) => ControllerBuilder.Current);

            container.Export <ControllerTypeResolverFactory>().As <IControllerTypeResolverFactory>()
            .WithCtorParam(() => new string[0]).Named("areaNamespacesToIgnore");

            // Configure Security
            string attributeModuleKey = typeof(AuthorizeAttributeAclModule).Name;
            container.Export <AuthorizeAttributeAclModule>()
            .As <IAclModule>()
            .WithKey(attributeModuleKey);

            string xmlModuleKey = typeof(XmlRolesAclModule).Name;
            container.Export <XmlRolesAclModule>()
            .As <IAclModule>()
            .WithKey(xmlModuleKey);

            container.Export <CompositeAclModule>()
            .As <IAclModule>()
            .WithCtorParam <IAclModule[]>().Named("aclModules").LocateWithKey(new[] { attributeModuleKey, xmlModuleKey });

            // Configure cache
            container.ExportInstance <System.Runtime.Caching.ObjectCache>(
                (scope, context) => System.Runtime.Caching.MemoryCache.Default);

            container.Export(typeof(RuntimeCacheProvider <>)).As(typeof(ICacheProvider <>));

            container.Export <RuntimeFileCacheDependency>()
            .As <ICacheDependency>()
            .WithKey("cacheDependency1")
            .WithCtorParam(() => absoluteFileName).Named("fileName");

            container.Export <CacheDetails>()
            .As <ICacheDetails>()
            .WithKey("cacheDetails1")
            .WithCtorParam <ICacheDependency>().LocateWithKey("cacheDependency1")
            .WithNamedCtorValue(() => absoluteCacheExpiration)
            .WithNamedCtorValue(() => slidingCacheExpiration);

            // Configure the visitors
            container.Export <UrlResolvingSiteMapNodeVisitor>().As <ISiteMapNodeVisitor>();

            // Prepare for our node providers
            container.Export <FileXmlSource>()
            .As <IXmlSource>()
            .WithKey("xmlSource1")
            .WithCtorParam(() => absoluteFileName);

            container.Export <ReservedAttributeNameProvider>().As <IReservedAttributeNameProvider>()
            .WithCtorParam(() => new string[0]).Named("attributesToIgnore");

            // Register the sitemap node providers
            container.Export <XmlSiteMapNodeProvider>()
            .As <ISiteMapNodeProvider>()
            .WithKey("xmlSiteMapNodeProvider1")
            .WithCtorParam <IXmlSource>().LocateWithKey("xmlSource1")
            .WithNamedCtorValue(() => includeRootNode)
            .WithNamedCtorValue(() => useNestedDynamicNodeRecursion);

            container.Export <ReflectionSiteMapNodeProvider>()
            .As <ISiteMapNodeProvider>()
            .WithKey("reflectionSiteMapNodeProvider1")
            .WithCtorParam(() => includeAssembliesForScan).Named("includeAssemblies")
            .WithCtorParam(() => new string[0]).Named("excludeAssemblies");

            container.Export <CompositeSiteMapNodeProvider>()
            .As <ISiteMapNodeProvider>()
            .WithKey("siteMapNodeProvider1")
            .WithCtorParam <ISiteMapNodeProvider[]>().LocateWithKey(new[]
            {
                "xmlSiteMapNodeProvider1",
                "reflectionSiteMapNodeProvider1"
            });

            // Register the sitemap builders
            container.Export <SiteMapBuilder>()
            .As <ISiteMapBuilder>()
            .WithKey("siteMapBuilder1")
            .WithCtorParam <ISiteMapNodeProvider>().Named("siteMapNodeProvider").LocateWithKey("siteMapNodeProvider1");

            // Configure the builder sets
            container.Export <SiteMapBuilderSet>()
            .As <ISiteMapBuilderSet>()
            .WithKey("builderSet1")
            .WithCtorParam(() => "default").Named("instanceName")
            .WithCtorParam <ISiteMapBuilder>().Named("siteMapBuilder").LocateWithKey("siteMapBuilder1")
            .WithCtorParam <ICacheDetails>().Named("cacheDetails").LocateWithKey("cacheDetails1")
            .WithNamedCtorValue(() => securityTrimmingEnabled)
            .WithNamedCtorValue(() => enableLocalization)
            .WithNamedCtorValue(() => visibilityAffectsDescendants)
            .WithNamedCtorValue(() => useTitleIfDescriptionNotProvided);

            container.Export <SiteMapBuilderSetStrategy>()
            .As <ISiteMapBuilderSetStrategy>()
            .WithCtorParam <ISiteMapBuilderSet[]>().Named("siteMapBuilderSets").LocateWithKey(new[] { "builderSet1" });
        }
        protected override void Load(ContainerBuilder builder)
        {
            bool     securityTrimmingEnabled = false;
            bool     enableLocalization      = true;
            string   absoluteFileName        = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5);

            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            var allAssemblies           = new Assembly[] { currentAssembly, siteMapProviderAssembly };
            var excludeTypes            = new Type[] {
                typeof(SiteMapNodeVisibilityProviderStrategy),
                typeof(SiteMapXmlReservedAttributeNameProvider),
                typeof(SiteMapBuilderSetStrategy)
            };
            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Single implementations of interface with matching name (minus the "I").
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => builder.RegisterType(implementationType).As(interfaceType).SingleInstance(),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => builder.RegisterType(implementationType).As(interfaceType).SingleInstance(),
                multipleImplementationTypes,
                allAssemblies,
                excludeTypes,
                "^Composite");

            // Registration of internal controllers
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => builder.RegisterType(implementationType).As(interfaceType).AsSelf().InstancePerDependency(),
                new Type[] { typeof(IController) },
                new Assembly[] { siteMapProviderAssembly },
                new Type[0],
                string.Empty);

            // Visibility Providers
            builder.RegisterType <SiteMapNodeVisibilityProviderStrategy>()
            .As <ISiteMapNodeVisibilityProviderStrategy>()
            .WithParameter("defaultProviderName", string.Empty);

            // Pass in the global controllerBuilder reference
            builder.RegisterInstance(ControllerBuilder.Current)
            .As <ControllerBuilder>();

            builder.RegisterType <BuildManagerAdaptor>()
            .As <IBuildManager>();

            builder.RegisterType <ControllerBuilderAdaptor>()
            .As <IControllerBuilder>();

            builder.RegisterType <ControllerTypeResolverFactory>()
            .As <IControllerTypeResolverFactory>()
            .WithParameter("areaNamespacesToIgnore", new string[0]);

            // Configure Security
            builder.RegisterType <AuthorizeAttributeAclModule>()
            .Named <IAclModule>("authorizeAttributeAclModule");
            builder.RegisterType <XmlRolesAclModule>()
            .Named <IAclModule>("xmlRolesAclModule");
            builder.RegisterType <CompositeAclModule>()
            .As <IAclModule>()
            .WithParameter(
                (p, c) => p.Name == "aclModules",
                (p, c) => new[]
            {
                c.ResolveNamed <IAclModule>("authorizeAttributeAclModule"),
                c.ResolveNamed <IAclModule>("xmlRolesAclModule")
            });

#if NET35
            builder.RegisterGeneric(typeof(AspNetCacheProvider <>))
            .As(typeof(ICacheProvider <>));

            builder.RegisterType <AspNetFileCacheDependency>()
            .Named <ICacheDependency>("cacheDependency1")
            .WithParameter("fileName", absoluteFileName);
#else
            builder.RegisterInstance(System.Runtime.Caching.MemoryCache.Default)
            .As <System.Runtime.Caching.ObjectCache>();

            builder.RegisterGeneric(typeof(RuntimeCacheProvider <>))
            .As(typeof(ICacheProvider <>));

            builder.RegisterType <RuntimeFileCacheDependency>()
            .Named <ICacheDependency>("cacheDependency1")
            .WithParameter("fileName", absoluteFileName);
#endif
            builder.RegisterType <CacheDetails>()
            .Named <ICacheDetails>("cacheDetails1")
            .WithParameter("absoluteCacheExpiration", absoluteCacheExpiration)
            .WithParameter("slidingCacheExpiration", TimeSpan.MinValue)
            .WithParameter(
                (p, c) => p.Name == "cacheDependency",
                (p, c) => c.ResolveNamed <ICacheDependency>("cacheDependency1"));

            // Configure the visitors
            builder.RegisterType <UrlResolvingSiteMapNodeVisitor>()
            .As <ISiteMapNodeVisitor>();

            // Prepare for our node providers
            builder.RegisterType <FileXmlSource>()
            .Named <IXmlSource>("xmlSource1")
            .WithParameter("fileName", absoluteFileName);

            builder.RegisterType <SiteMapXmlReservedAttributeNameProvider>()
            .As <ISiteMapXmlReservedAttributeNameProvider>()
            .WithParameter("attributesToIgnore", new string[0]);


            // Register the sitemap node providers
            builder.RegisterType <XmlSiteMapNodeProvider>()
            .Named <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1")
            .WithParameter("includeRootNode", true)
            .WithParameter("useNestedDynamicNodeRecursion", false)
            .WithParameter(
                (p, c) => p.Name == "xmlSource",
                (p, c) => c.ResolveNamed <IXmlSource>("xmlSource1"));

            builder.RegisterType <ReflectionSiteMapNodeProvider>()
            .Named <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
            .WithParameter("includeAssemblies", includeAssembliesForScan)
            .WithParameter("excludeAssemblies", new string[0]);

            builder.RegisterType <CompositeSiteMapNodeProvider>()
            .Named <ISiteMapNodeProvider>("siteMapNodeProvider1")
            .WithParameter(
                (p, c) => p.Name == "siteMapNodeProviders",
                (p, c) => new[]
            {
                c.ResolveNamed <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                c.ResolveNamed <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
            });

            // Register the sitemap builders
            builder.RegisterType <SiteMapBuilder>()
            .Named <ISiteMapBuilder>("siteMapBuilder1")
            .WithParameter(
                (p, c) => p.Name == "siteMapNodeProvider",
                (p, c) => c.ResolveNamed <ISiteMapNodeProvider>("siteMapNodeProvider1"));

            // Configure the builder sets
            builder.RegisterType <SiteMapBuilderSet>()
            .Named <ISiteMapBuilderSet>("builderSet1")
            .WithParameter("instanceName", "default")
            .WithParameter("securityTrimmingEnabled", securityTrimmingEnabled)
            .WithParameter("enableLocalization", enableLocalization)
            .WithParameter(
                (p, c) => p.Name == "siteMapBuilder",
                (p, c) => c.ResolveNamed <ISiteMapBuilder>("siteMapBuilder1"))
            .WithParameter(
                (p, c) => p.Name == "cacheDetails",
                (p, c) => c.ResolveNamed <ICacheDetails>("cacheDetails1"));

            builder.RegisterType <SiteMapBuilderSetStrategy>()
            .As <ISiteMapBuilderSetStrategy>()
            .WithParameter(
                (p, c) => p.Name == "siteMapBuilderSets",
                (p, c) => c.ResolveNamed <IEnumerable <ISiteMapBuilderSet> >("builderSet1"));
        }
        protected override void Load(ContainerBuilder builder)
        {
            bool     enableLocalization               = true;
            string   absoluteFileName                 = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            bool     visibilityAffectsDescendants     = true;
            bool     useTitleIfDescriptionNotProvided = true;



            bool securityTrimmingEnabled = false;

            string[] includeAssembliesForScan = new string[] { "RafflesChart" };


            var currentAssembly             = this.GetType().Assembly;
            var siteMapProviderAssembly     = typeof(SiteMaps).Assembly;
            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),
                typeof(IDynamicNodeProvider)
            };

// Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
// and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => builder.RegisterType(implementationType).As(interfaceType).SingleInstance(),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

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

// Registration of internal controllers
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => builder.RegisterType(implementationType).As(interfaceType).AsSelf().InstancePerDependency(),
                new Type[] { typeof(IController) },
                new Assembly[] { siteMapProviderAssembly },
                new Type[0],
                string.Empty);

// Visibility Providers
            builder.RegisterType <SiteMapNodeVisibilityProviderStrategy>()
            .As <ISiteMapNodeVisibilityProviderStrategy>()
            .WithParameter("defaultProviderName", string.Empty);

// Pass in the global controllerBuilder reference
            builder.RegisterInstance(ControllerBuilder.Current)
            .As <ControllerBuilder>();

            builder.RegisterType <ControllerTypeResolverFactory>()
            .As <IControllerTypeResolverFactory>()
            .WithParameter("areaNamespacesToIgnore", new string[0]);

// Configure Security
            builder.RegisterType <AuthorizeAttributeAclModule>()
            .Named <IAclModule>("authorizeAttributeAclModule");
            builder.RegisterType <XmlRolesAclModule>()
            .Named <IAclModule>("xmlRolesAclModule");
            builder.RegisterType <CompositeAclModule>()
            .As <IAclModule>()
            .WithParameter(
                (p, c) => p.Name == "aclModules",
                (p, c) => new[]
            {
                c.ResolveNamed <IAclModule>("authorizeAttributeAclModule"),
                c.ResolveNamed <IAclModule>("xmlRolesAclModule")
            });



            builder.RegisterInstance(System.Runtime.Caching.MemoryCache.Default)
            .As <System.Runtime.Caching.ObjectCache>();

            builder.RegisterGeneric(typeof(RuntimeCacheProvider <>))
            .As(typeof(ICacheProvider <>));

            builder.RegisterType <RuntimeFileCacheDependency>()
            .Named <ICacheDependency>("cacheDependency1")
            .WithParameter("fileName", absoluteFileName);

            builder.RegisterType <CacheDetails>()
            .Named <ICacheDetails>("cacheDetails1")
            .WithParameter("absoluteCacheExpiration", absoluteCacheExpiration)
            .WithParameter("slidingCacheExpiration", TimeSpan.MinValue)
            .WithParameter(
                (p, c) => p.Name == "cacheDependency",
                (p, c) => c.ResolveNamed <ICacheDependency>("cacheDependency1"));

// Configure the visitors
            builder.RegisterType <UrlResolvingSiteMapNodeVisitor>()
            .As <ISiteMapNodeVisitor>();

// Prepare for our node providers
            builder.RegisterType <FileXmlSource>()
            .Named <IXmlSource>("xmlSource1")
            .WithParameter("fileName", absoluteFileName);

            builder.RegisterType <ReservedAttributeNameProvider>()
            .As <IReservedAttributeNameProvider>()
            .WithParameter("attributesToIgnore", new string[0]);


// Register the sitemap node providers
            builder.RegisterType <XmlSiteMapNodeProvider>()
            .Named <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1")
            .WithParameter("includeRootNode", true)
            .WithParameter("useNestedDynamicNodeRecursion", false)
            .WithParameter(
                (p, c) => p.Name == "xmlSource",
                (p, c) => c.ResolveNamed <IXmlSource>("xmlSource1"));

            builder.RegisterType <ReflectionSiteMapNodeProvider>()
            .Named <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
            .WithParameter("includeAssemblies", includeAssembliesForScan)
            .WithParameter("excludeAssemblies", new string[0]);

            builder.RegisterType <CompositeSiteMapNodeProvider>()
            .Named <ISiteMapNodeProvider>("siteMapNodeProvider1")
            .WithParameter(
                (p, c) => p.Name == "siteMapNodeProviders",
                (p, c) => new[]
            {
                c.ResolveNamed <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                c.ResolveNamed <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
            });

// Register the sitemap builders
            builder.RegisterType <SiteMapBuilder>()
            .Named <ISiteMapBuilder>("siteMapBuilder1")
            .WithParameter(
                (p, c) => p.Name == "siteMapNodeProvider",
                (p, c) => c.ResolveNamed <ISiteMapNodeProvider>("siteMapNodeProvider1"));

// Configure the builder sets
            builder.RegisterType <SiteMapBuilderSet>()
            .Named <ISiteMapBuilderSet>("builderSet1")
            .WithParameter("instanceName", "default")
            .WithParameter("securityTrimmingEnabled", securityTrimmingEnabled)
            .WithParameter("enableLocalization", enableLocalization)
            .WithParameter("visibilityAffectsDescendants", visibilityAffectsDescendants)
            .WithParameter("useTitleIfDescriptionNotProvided", useTitleIfDescriptionNotProvided)
            .WithParameter(
                (p, c) => p.Name == "siteMapBuilder",
                (p, c) => c.ResolveNamed <ISiteMapBuilder>("siteMapBuilder1"))
            .WithParameter(
                (p, c) => p.Name == "cacheDetails",
                (p, c) => c.ResolveNamed <ICacheDetails>("cacheDetails1"));

            builder.RegisterType <SiteMapBuilderSetStrategy>()
            .As <ISiteMapBuilderSetStrategy>()
            .WithParameter(
                (p, c) => p.Name == "siteMapBuilderSets",
                (p, c) => c.ResolveNamed <IEnumerable <ISiteMapBuilderSet> >("builderSet1"));
        }
Пример #4
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            bool     securityTrimmingEnabled = false;
            bool     enableLocalization      = true;
            string   absoluteFileName        = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5);

            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };

            // Configure Windsor to resolve arrays in constructors
            container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel, true));

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            var allAssemblies           = new Assembly[] { currentAssembly, siteMapProviderAssembly };
            var excludeTypes            = new Type[] {
                typeof(SiteMapNodeVisibilityProviderStrategy),
                typeof(SiteMapXmlReservedAttributeNameProvider),
                typeof(SiteMapBuilderSetStrategy),
                typeof(ControllerTypeResolverFactory),
                typeof(SiteMapNodeUrlResolver)
            };
            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Single implementations of interface with matching name (minus the "I").
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => container.Register(Component.For(interfaceType).ImplementedBy(implementationType).LifestyleSingleton()),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => container.Register(Component.For(interfaceType).ImplementedBy(implementationType).LifestyleSingleton()),
                multipleImplementationTypes,
                allAssemblies,
                new Type[0],
                "^Composite");

            // Registration of internal controllers
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => container.Register(Component.For(implementationType).ImplementedBy(implementationType).LifestyleTransient()),
                new Type[] { typeof(IController) },
                new Assembly[] { siteMapProviderAssembly },
                new Type[0],
                string.Empty);

            // Visibility Providers
            container.Register(Component.For <ISiteMapNodeVisibilityProviderStrategy>().ImplementedBy <SiteMapNodeVisibilityProviderStrategy>()
                               .DependsOn(Dependency.OnValue("defaultProviderName", string.Empty)));

            // Pass in the global controllerBuilder reference
            container.Register(Component.For <ControllerBuilder>().Instance(ControllerBuilder.Current));
            container.Register(Component.For <IControllerBuilder>().ImplementedBy <ControllerBuilderAdaptor>());
            container.Register(Component.For <IBuildManager>().ImplementedBy <BuildManagerAdaptor>());
            container.Register(Component.For <IControllerTypeResolverFactory>().ImplementedBy <ControllerTypeResolverFactory>()
                               .DependsOn(Dependency.OnValue("areaNamespacesToIgnore", new string[0])));

            // Configure Security

            // First registration wins - we must do the outer one first
            container.Register(Component.For <IAclModule>().ImplementedBy <CompositeAclModule>()
                               .DependsOn(Dependency.OnComponentCollection <IEnumerable <IAclModule> >(typeof(AuthorizeAttributeAclModule), typeof(XmlRolesAclModule))));

            container.Register(Component.For <IAclModule>().ImplementedBy <AuthorizeAttributeAclModule>());
            container.Register(Component.For <IAclModule>().ImplementedBy <XmlRolesAclModule>());


            // Setup cache
#if NET35
            container.Register(Component.For(typeof(ICacheProvider <>)).ImplementedBy(typeof(AspNetCacheProvider <>)));
            container.Register(Component.For <ICacheDependency>().ImplementedBy <AspNetFileCacheDependency>().Named("cacheDependency1")
                               .DependsOn(Dependency.OnValue("fileName", absoluteFileName)));
#else
            container.Register(Component.For <System.Runtime.Caching.ObjectCache>().Instance(System.Runtime.Caching.MemoryCache.Default));
            container.Register(Component.For(typeof(ICacheProvider <>)).ImplementedBy(typeof(RuntimeCacheProvider <>)));
            container.Register(Component.For <ICacheDependency>().ImplementedBy <RuntimeFileCacheDependency>().Named("cacheDependency1")
                               .DependsOn(Dependency.OnValue("fileName", absoluteFileName)));
#endif
            container.Register(Component.For <ICacheDetails>().ImplementedBy <CacheDetails>().Named("cacheDetails1")
                               .DependsOn(Dependency.OnValue("absoluteCacheExpiration", absoluteCacheExpiration))
                               .DependsOn(Dependency.OnValue("slidingCacheExpiration", TimeSpan.MinValue))
                               .DependsOn(ServiceOverride.ForKey <ICacheDependency>().Eq("cacheDependency1"))
                               );

            // Configure the visitors
            container.Register(Component.For <ISiteMapNodeVisitor>().ImplementedBy <UrlResolvingSiteMapNodeVisitor>());

            // Register the sitemap builder
            container.Register(Component.For <IXmlSource>().ImplementedBy <FileXmlSource>().Named("xmlSource1")
                               .DependsOn(Dependency.OnValue("fileName", absoluteFileName)));
            container.Register(Component.For <ISiteMapXmlReservedAttributeNameProvider>().ImplementedBy <SiteMapXmlReservedAttributeNameProvider>()
                               .DependsOn(Dependency.OnValue("attributesToIgnore", new string[0])));

            container.Register(Component.For <ISiteMapBuilder>().ImplementedBy <CompositeSiteMapBuilder>().Named("builder1")
                               .DependsOn(Dependency.OnComponentCollection <ISiteMapBuilder[]>("xmlSiteMapBuilder1", "reflectionSiteMapBuilder1", "visitingSiteMapBuilder1")));

            container.Register(Component.For <ISiteMapBuilder>().ImplementedBy <XmlSiteMapBuilder>().Named("xmlSiteMapBuilder1")
                               .DependsOn(Dependency.OnValue <ISiteMapXmlReservedAttributeNameProvider>(container.Resolve <ISiteMapXmlReservedAttributeNameProvider>()))
                               .DependsOn(ServiceOverride.ForKey <IXmlSource>().Eq("xmlSource1"))
                               );

            container.Register(Component.For <ISiteMapBuilder>().ImplementedBy <ReflectionSiteMapBuilder>().Named("reflectionSiteMapBuilder1")
                               .DependsOn(Dependency.OnValue("includeAssemblies", includeAssembliesForScan))
                               .DependsOn(Dependency.OnValue("excludeAssemblies", new string[0]))
                               );

            container.Register(Component.For <ISiteMapBuilder>().ImplementedBy <VisitingSiteMapBuilder>().Named("visitingSiteMapBuilder1"));

            // Configure the builder sets
            container.Register(Component.For <ISiteMapBuilderSet>().ImplementedBy <SiteMapBuilderSet>().Named("siteMapBuilderSet1")
                               .DependsOn(Dependency.OnValue("instanceName", "default"))
                               .DependsOn(Dependency.OnValue("securityTrimmingEnabled", securityTrimmingEnabled))
                               .DependsOn(Dependency.OnValue("enableLocalization", enableLocalization))
                               .DependsOn(ServiceOverride.ForKey <ISiteMapBuilder>().Eq("builder1"))
                               .DependsOn(ServiceOverride.ForKey <ICacheDetails>().Eq("cacheDetails1"))
                               );

            container.Register(Component.For <ISiteMapBuilderSetStrategy>().ImplementedBy <SiteMapBuilderSetStrategy>()
                               .DependsOn(Dependency.OnComponentCollection <ISiteMapBuilderSet[]>("siteMapBuilderSet1")));
        }
        public override void Load()
        {
            bool     securityTrimmingEnabled = false;
            bool     enableLocalization      = true;
            string   absoluteFileName        = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5);

            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            var allAssemblies           = new Assembly[] { currentAssembly, siteMapProviderAssembly };
            var excludeTypes            = new Type[] {
                typeof(SiteMapNodeVisibilityProviderStrategy),
                typeof(SiteMapXmlReservedAttributeNameProvider),
                typeof(SiteMapBuilderSetStrategy)
            };
            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Single implementations of interface with matching name (minus the "I").
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => this.Kernel.Bind(interfaceType).To(implementationType).InSingletonScope(),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => this.Kernel.Bind(interfaceType).To(implementationType).InSingletonScope(),
                multipleImplementationTypes,
                allAssemblies,
                excludeTypes,
                "^Composite");

            this.Kernel.Bind <ISiteMapNodeVisibilityProviderStrategy>().To <SiteMapNodeVisibilityProviderStrategy>()
            .WithConstructorArgument("defaultProviderName", string.Empty);

            this.Kernel.Bind <ControllerBuilder>().ToConstant(ControllerBuilder.Current);
            this.Kernel.Bind <IControllerBuilder>().To <ControllerBuilderAdaptor>();
            this.Kernel.Bind <IBuildManager>().To <BuildManagerAdaptor>();

            // Configure Security
            this.Kernel.Bind <AuthorizeAttributeAclModule>().ToSelf();
            this.Kernel.Bind <XmlRolesAclModule>().ToSelf();
            this.Kernel.Bind <IAclModule>().To <CompositeAclModule>()
            .WithConstructorArgument("aclModules",
                                     new IAclModule[] {
                this.Kernel.Get <AuthorizeAttributeAclModule>(),
                this.Kernel.Get <XmlRolesAclModule>()
            });


            // Setup cache
#if NET35
            this.Kernel.Bind(typeof(ICacheProvider <>)).To(typeof(AspNetCacheProvider <>));
            this.Kernel.Bind <ICacheDependency>().To <AspNetFileCacheDependency>().Named("cacheDependency1")
            .WithConstructorArgument("fileName", absoluteFileName);
#else
            this.Kernel.Bind <System.Runtime.Caching.ObjectCache>()
            .ToConstant <System.Runtime.Caching.ObjectCache>(System.Runtime.Caching.MemoryCache.Default);
            this.Kernel.Bind(typeof(ICacheProvider <>)).To(typeof(RuntimeCacheProvider <>));
            this.Kernel.Bind <ICacheDependency>().To <RuntimeFileCacheDependency>().Named("cacheDependency1")
            .WithConstructorArgument("fileName", absoluteFileName);
#endif
            this.Kernel.Bind <ICacheDetails>().To <CacheDetails>().Named("cacheDetails1")
            .WithConstructorArgument("absoluteCacheExpiration", absoluteCacheExpiration)
            .WithConstructorArgument("slidingCacheExpiration", TimeSpan.MinValue)
            .WithConstructorArgument("cacheDependency", this.Kernel.Get <ICacheDependency>("cacheDependency1"));


            // Configure the visitors
            this.Kernel.Bind <ISiteMapNodeVisitor>().To <UrlResolvingSiteMapNodeVisitor>();

            // Prepare for our node providers
            this.Kernel.Bind <IXmlSource>().To <FileXmlSource>().Named("XmlSource1")
            .WithConstructorArgument("fileName", absoluteFileName);
            this.Kernel.Bind <ISiteMapXmlReservedAttributeNameProvider>().To <SiteMapXmlReservedAttributeNameProvider>().Named("xmlBuilderReservedAttributeNameProvider")
            .WithConstructorArgument("attributesToIgnore", new string[0]);

            // Register the sitemap node providers
            this.Kernel.Bind <ISiteMapNodeProvider>().To <XmlSiteMapNodeProvider>().Named("xmlSiteMapNodeProvider1")
            .WithConstructorArgument("includeRootNode", true)
            .WithConstructorArgument("useNestedDynamicNodeRecursion", false)
            .WithConstructorArgument("xmlSource", this.Kernel.Get <IXmlSource>("XmlSource1"));

            this.Kernel.Bind <ISiteMapNodeProvider>().To <ReflectionSiteMapNodeProvider>().Named("reflectionSiteMapNodeProvider1")
            .WithConstructorArgument("includeAssemblies", includeAssembliesForScan)
            .WithConstructorArgument("excludeAssemblies", new string[0]);

            this.Kernel.Bind <ISiteMapNodeProvider>().To <CompositeSiteMapNodeProvider>().Named("siteMapNodeProvider1")
            .WithConstructorArgument("siteMapNodeProviders",
                                     new ISiteMapNodeProvider[] {
                this.Kernel.Get <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                this.Kernel.Get <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
            });

            // Register the sitemap builders
            this.Kernel.Bind <ISiteMapBuilder>().To <SiteMapBuilder>().Named("siteMapBuilder1")
            .WithConstructorArgument("siteMapNodeProvider", this.Kernel.Get <ISiteMapNodeProvider>("siteMapNodeProvider1"));

            // Configure the builder sets
            this.Kernel.Bind <ISiteMapBuilderSet>().To <SiteMapBuilderSet>().Named("siteMapBuilderSet1")
            .WithConstructorArgument("instanceName", "default")
            .WithConstructorArgument("securityTrimmingEnabled", securityTrimmingEnabled)
            .WithConstructorArgument("enableLocalization", enableLocalization)
            .WithConstructorArgument("siteMapBuilder", this.Kernel.Get <ISiteMapBuilder>("siteMapBuilder1"))
            .WithConstructorArgument("cacheDetails", this.Kernel.Get <ICacheDetails>("cacheDetails1"));

            this.Kernel.Bind <ISiteMapBuilderSetStrategy>().To <SiteMapBuilderSetStrategy>()
            .WithConstructorArgument("siteMapBuilderSets",
                                     new ISiteMapBuilderSet[] {
                this.Kernel.Get <ISiteMapBuilderSet>("siteMapBuilderSet1")
            });
        }
Пример #6
0
        protected override void Initialize()
        {
            bool     securityTrimmingEnabled = false;
            bool     enableLocalization      = true;
            string   absoluteFileName        = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5);

            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            var allAssemblies           = new Assembly[] { currentAssembly, siteMapProviderAssembly };
            var excludeTypes            = new Type[] {
                typeof(SiteMapNodeVisibilityProviderStrategy),
                typeof(SiteMapXmlReservedAttributeNameProvider),
                typeof(SiteMapBuilderSetStrategy),
                typeof(SiteMapNodeUrlResolverStrategy),
                typeof(DynamicNodeProviderStrategy)
            };
            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Single implementations of interface with matching name (minus the "I").
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, new ContainerControlledLifetimeManager()),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, implementationType.Name, new ContainerControlledLifetimeManager()),
                multipleImplementationTypes,
                allAssemblies,
                excludeTypes,
                "^Composite");

            // TODO: Find a better way to inject an array constructor

            // Url Resolvers
            this.Container.RegisterType <ISiteMapNodeUrlResolverStrategy, SiteMapNodeUrlResolverStrategy>(new InjectionConstructor(
                                                                                                              new ResolvedArrayParameter <ISiteMapNodeUrlResolver>(this.Container.ResolveAll <ISiteMapNodeUrlResolver>().ToArray())
                                                                                                              ));

            // Visibility Providers
            this.Container.RegisterType <ISiteMapNodeVisibilityProviderStrategy, SiteMapNodeVisibilityProviderStrategy>(new InjectionConstructor(
                                                                                                                            new ResolvedArrayParameter <ISiteMapNodeVisibilityProvider>(this.Container.ResolveAll <ISiteMapNodeVisibilityProvider>().ToArray()),
                                                                                                                            new InjectionParameter <string>(string.Empty)
                                                                                                                            ));

            // Dynamic Node Providers
            this.Container.RegisterType <IDynamicNodeProviderStrategy, DynamicNodeProviderStrategy>(new InjectionConstructor(
                                                                                                        new ResolvedArrayParameter <IDynamicNodeProvider>(this.Container.ResolveAll <IDynamicNodeProvider>().ToArray())
                                                                                                        ));


            // Pass in the global controllerBuilder reference
            this.Container.RegisterInstance <ControllerBuilder>(ControllerBuilder.Current);
            this.Container.RegisterType <IControllerBuilder, ControllerBuilderAdaptor>(new PerResolveLifetimeManager());

            this.Container.RegisterType <IBuildManager, BuildManagerAdaptor>(new PerResolveLifetimeManager());

            this.Container.RegisterType <IControllerTypeResolverFactory, ControllerTypeResolverFactory>(new InjectionConstructor(
                                                                                                            new List <string>(),
                                                                                                            new ResolvedParameter <IControllerBuilder>(),
                                                                                                            new ResolvedParameter <IBuildManager>()));

            // Configure Security

            // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
            this.Container.RegisterType <IAclModule, AuthorizeAttributeAclModule>("authorizeAttribute");
            this.Container.RegisterType <IAclModule, XmlRolesAclModule>("xmlRoles");
            this.Container.RegisterType <IAclModule, CompositeAclModule>(new InjectionConstructor(new ResolvedArrayParameter <IAclModule>(
                                                                                                      new ResolvedParameter <IAclModule>("authorizeAttribute"),
                                                                                                      new ResolvedParameter <IAclModule>("xmlRoles"))));

#if NET35
            this.Container.RegisterType(typeof(ICacheProvider <>), typeof(AspNetCacheProvider <>));
            this.Container.RegisterType <ICacheDependency, AspNetFileCacheDependency>(
                "cacheDependency", new InjectionConstructor(absoluteFileName));
#else
            this.Container.RegisterInstance <System.Runtime.Caching.ObjectCache>(System.Runtime.Caching.MemoryCache.Default);
            this.Container.RegisterType(typeof(ICacheProvider <>), typeof(RuntimeCacheProvider <>));
            this.Container.RegisterType <ICacheDependency, RuntimeFileCacheDependency>(
                "cacheDependency", new InjectionConstructor(absoluteFileName));
#endif
            this.Container.RegisterType <ICacheDetails, CacheDetails>("cacheDetails",
                                                                      new InjectionConstructor(absoluteCacheExpiration, TimeSpan.MinValue, new ResolvedParameter <ICacheDependency>("cacheDependency")));

            // Configure the visitors
            this.Container.RegisterType <ISiteMapNodeVisitor, UrlResolvingSiteMapNodeVisitor>();

            // Prepare for the sitemap node providers
            this.Container.RegisterType <IXmlSource, FileXmlSource>("file1XmlSource", new InjectionConstructor(absoluteFileName));
            this.Container.RegisterType <ISiteMapXmlReservedAttributeNameProvider, SiteMapXmlReservedAttributeNameProvider>(new InjectionConstructor(new List <string>()));

            // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
            // Register the sitemap node providers
            this.Container.RegisterInstance <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1",
                                                                   this.Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(this.Container.Resolve <IXmlSource>("file1XmlSource")), new ContainerControlledLifetimeManager());
            this.Container.RegisterInstance <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1",
                                                                   this.Container.Resolve <ReflectionSiteMapNodeProviderFactory>().Create(includeAssembliesForScan), new ContainerControlledLifetimeManager());
            this.Container.RegisterType <ISiteMapNodeProvider, CompositeSiteMapNodeProvider>(new InjectionConstructor(new ResolvedArrayParameter <ISiteMapNodeProvider>(
                                                                                                                          new ResolvedParameter <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                                                                                                                          new ResolvedParameter <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1"))));

            // Configure the builders
            this.Container.RegisterType <ISiteMapBuilder, SiteMapBuilder>();

            // Configure the builder sets
            this.Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("builderSet1",
                                                                                new InjectionConstructor(
                                                                                    "default",
                                                                                    securityTrimmingEnabled,
                                                                                    enableLocalization,
                                                                                    new ResolvedParameter <ISiteMapBuilder>(),
                                                                                    new ResolvedParameter <ICacheDetails>("cacheDetails")));

            this.Container.RegisterType <ISiteMapBuilderSetStrategy, SiteMapBuilderSetStrategy>(new InjectionConstructor(new ResolvedArrayParameter <ISiteMapBuilderSet>(new ResolvedParameter <ISiteMapBuilderSet>("builderSet1"))));
        }
Пример #7
0
        protected override void Initialize()
        {
            bool     enableLocalization               = true;
            string   absoluteFileName                 = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            bool     visibilityAffectsDescendants     = true;
            bool     useTitleIfDescriptionNotProvided = true;



            bool securityTrimmingEnabled = true;

            string[] includeAssembliesForScan = new string[] { "JB.Sample.MvcSiteMap.Website" };


            var currentAssembly             = this.GetType().Assembly;
            var siteMapProviderAssembly     = typeof(SiteMaps).Assembly;
            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),
                typeof(IDynamicNodeProvider)
            };

            // Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
            // and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, new ContainerControlledLifetimeManager()),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // 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);

            // TODO: Find a better way to inject an array constructor

            // Url Resolvers
            this.Container.RegisterType <ISiteMapNodeUrlResolverStrategy, SiteMapNodeUrlResolverStrategy>(new InjectionConstructor(
                                                                                                              new ResolvedArrayParameter <ISiteMapNodeUrlResolver>(this.Container.ResolveAll <ISiteMapNodeUrlResolver>().ToArray())
                                                                                                              ));

            // CacheKey Generator
            this.Container.RegisterType <ISiteMapCacheKeyGenerator, SessionBasedSiteMapCacheKeyGenerator>();


            // Visibility Providers
            this.Container.RegisterType <ISiteMapNodeVisibilityProviderStrategy, SiteMapNodeVisibilityProviderStrategy>(new InjectionConstructor(
                                                                                                                            new ResolvedArrayParameter <ISiteMapNodeVisibilityProvider>(this.Container.ResolveAll <ISiteMapNodeVisibilityProvider>().ToArray()),
                                                                                                                            new InjectionParameter <string>(string.Empty)
                                                                                                                            ));

            // Dynamic Node Providers
            this.Container.RegisterType <IDynamicNodeProviderStrategy, DynamicNodeProviderStrategy>(new InjectionConstructor(
                                                                                                        new ResolvedArrayParameter <IDynamicNodeProvider>(this.Container.ResolveAll <IDynamicNodeProvider>().ToArray())
                                                                                                        ));


            // Pass in the global controllerBuilder reference
            this.Container.RegisterInstance <ControllerBuilder>(ControllerBuilder.Current);

            this.Container.RegisterType <IControllerTypeResolverFactory, ControllerTypeResolverFactory>(new InjectionConstructor(
                                                                                                            new List <string>(),
                                                                                                            new ResolvedParameter <IControllerBuilder>(),
                                                                                                            new ResolvedParameter <IBuildManager>()));

            // Configure Security

            // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
            this.Container.RegisterType <IAclModule, AuthorizeAttributeAclModule>("authorizeAttribute");
            this.Container.RegisterType <IAclModule, XmlRolesAclModule>("xmlRoles");
            this.Container.RegisterType <IAclModule, CompositeAclModule>(new InjectionConstructor(new ResolvedArrayParameter <IAclModule>(
                                                                                                      new ResolvedParameter <IAclModule>("authorizeAttribute"),
                                                                                                      new ResolvedParameter <IAclModule>("xmlRoles"))));



            this.Container.RegisterInstance <System.Runtime.Caching.ObjectCache>(System.Runtime.Caching.MemoryCache.Default);
            this.Container.RegisterType(typeof(ICacheProvider <>), typeof(RuntimeCacheProvider <>));
            this.Container.RegisterType <ICacheDependency, RuntimeFileCacheDependency>(
                "cacheDependency", new InjectionConstructor(absoluteFileName));

            this.Container.RegisterType <ICacheDetails, CacheDetails>("cacheDetails",
                                                                      new InjectionConstructor(absoluteCacheExpiration, TimeSpan.MinValue, new ResolvedParameter <ICacheDependency>("cacheDependency")));

            // Configure the visitors
            this.Container.RegisterType <ISiteMapNodeVisitor, UrlResolvingSiteMapNodeVisitor>();

            // Prepare for the sitemap node providers
            this.Container.RegisterType <IXmlSource, FileXmlSource>("file1XmlSource", new InjectionConstructor(absoluteFileName));
            this.Container.RegisterType <IReservedAttributeNameProvider, ReservedAttributeNameProvider>(new InjectionConstructor(new List <string>()));

            // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
            // Register the sitemap node providers
            this.Container.RegisterInstance <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1",
                                                                   this.Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(this.Container.Resolve <IXmlSource>("file1XmlSource")), new ContainerControlledLifetimeManager());
            this.Container.RegisterInstance <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1",
                                                                   this.Container.Resolve <ReflectionSiteMapNodeProviderFactory>().Create(includeAssembliesForScan), new ContainerControlledLifetimeManager());
            this.Container.RegisterType <ISiteMapNodeProvider, CompositeSiteMapNodeProvider>(new InjectionConstructor(new ResolvedArrayParameter <ISiteMapNodeProvider>(
                                                                                                                          new ResolvedParameter <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                                                                                                                          new ResolvedParameter <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1"))));

            // Configure the builders
            this.Container.RegisterType <ISiteMapBuilder, SiteMapBuilder>();

            // Configure the builder sets
            this.Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("builderSet1",
                                                                                new InjectionConstructor(
                                                                                    "default",
                                                                                    securityTrimmingEnabled,
                                                                                    enableLocalization,
                                                                                    visibilityAffectsDescendants,
                                                                                    useTitleIfDescriptionNotProvided,
                                                                                    new ResolvedParameter <ISiteMapBuilder>(),
                                                                                    new ResolvedParameter <ICacheDetails>("cacheDetails")));

            this.Container.RegisterType <ISiteMapBuilderSetStrategy, SiteMapBuilderSetStrategy>(new InjectionConstructor(
                                                                                                    new ResolvedArrayParameter <ISiteMapBuilderSet>(new ResolvedParameter <ISiteMapBuilderSet>("builderSet1"))));
        }
Пример #8
0
        public MvcSiteMapProviderRegistry()
        {
            bool     enableLocalization               = true;
            string   absoluteFileName                 = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            bool     visibilityAffectsDescendants     = true;
            bool     useTitleIfDescriptionNotProvided = true;



            bool securityTrimmingEnabled = false;

            string[] includeAssembliesForScan = new string[] { "QEP.ONRR.Web" };


            var currentAssembly             = this.GetType().Assembly;
            var siteMapProviderAssembly     = typeof(SiteMaps).Assembly;
            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),
                typeof(IDynamicNodeProvider)
            };

// Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
// and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => this.For(interfaceType).Singleton().Use(implementationType),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

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

// Visibility Providers
            this.For <ISiteMapNodeVisibilityProviderStrategy>().Use <SiteMapNodeVisibilityProviderStrategy>()
            .Ctor <string>("defaultProviderName").Is(string.Empty);

// Pass in the global controllerBuilder reference
            this.For <ControllerBuilder>()
            .Use(x => ControllerBuilder.Current);

            this.For <IControllerTypeResolverFactory>().Use <ControllerTypeResolverFactory>()
            .Ctor <string[]>("areaNamespacesToIgnore").Is(new string[0]);

// Configure Security
            this.For <IAclModule>().Use <CompositeAclModule>()
            .EnumerableOf <IAclModule>().Contains(x =>
            {
                x.Type <AuthorizeAttributeAclModule>();
                x.Type <XmlRolesAclModule>();
            });

// Setup cache
            SmartInstance <CacheDetails> cacheDetails;


            this.For <System.Runtime.Caching.ObjectCache>()
            .Use(s => System.Runtime.Caching.MemoryCache.Default);

            this.For(typeof(ICacheProvider <>)).Use(typeof(RuntimeCacheProvider <>));

            var cacheDependency =
                this.For <ICacheDependency>().Use <RuntimeFileCacheDependency>()
                .Ctor <string>("fileName").Is(absoluteFileName);

            cacheDetails =
                this.For <ICacheDetails>().Use <CacheDetails>()
                .Ctor <TimeSpan>("absoluteCacheExpiration").Is(absoluteCacheExpiration)
                .Ctor <TimeSpan>("slidingCacheExpiration").Is(TimeSpan.MinValue)
                .Ctor <ICacheDependency>().Is(cacheDependency);

// Configure the visitors
            this.For <ISiteMapNodeVisitor>()
            .Use <UrlResolvingSiteMapNodeVisitor>();


// Prepare for our node providers
            var xmlSource = this.For <IXmlSource>().Use <FileXmlSource>()
                            .Ctor <string>("fileName").Is(absoluteFileName);

            this.For <IReservedAttributeNameProvider>().Use <ReservedAttributeNameProvider>()
            .Ctor <IEnumerable <string> >("attributesToIgnore").Is(new string[0]);

// Register the sitemap node providers
            var siteMapNodeProvider = this.For <ISiteMapNodeProvider>().Use <CompositeSiteMapNodeProvider>()
                                      .EnumerableOf <ISiteMapNodeProvider>().Contains(x =>
            {
                x.Type <XmlSiteMapNodeProvider>()
                .Ctor <bool>("includeRootNode").Is(true)
                .Ctor <bool>("useNestedDynamicNodeRecursion").Is(false)
                .Ctor <IXmlSource>().Is(xmlSource);
                x.Type <ReflectionSiteMapNodeProvider>()
                .Ctor <IEnumerable <string> >("includeAssemblies").Is(includeAssembliesForScan)
                .Ctor <IEnumerable <string> >("excludeAssemblies").Is(new string[0]);
            });

// Register the sitemap builders
            var builder = this.For <ISiteMapBuilder>().Use <SiteMapBuilder>()
                          .Ctor <ISiteMapNodeProvider>().Is(siteMapNodeProvider);

// Configure the builder sets
            this.For <ISiteMapBuilderSetStrategy>().Use <SiteMapBuilderSetStrategy>()
            .EnumerableOf <ISiteMapBuilderSet>().Contains(x =>
            {
                x.Type <SiteMapBuilderSet>()
                .Ctor <string>("instanceName").Is("default")
                .Ctor <bool>("securityTrimmingEnabled").Is(securityTrimmingEnabled)
                .Ctor <bool>("enableLocalization").Is(enableLocalization)
                .Ctor <bool>("visibilityAffectsDescendants").Is(visibilityAffectsDescendants)
                .Ctor <bool>("useTitleIfDescriptionNotProvided").Is(useTitleIfDescriptionNotProvided)
                .Ctor <ISiteMapBuilder>().Is(builder)
                .Ctor <ICacheDetails>().Is(cacheDetails);
            });
        }
Пример #9
0
        public MvcSiteMapProviderRegistry()
        {
            bool     securityTrimmingEnabled = false;
            bool     enableLocalization      = true;
            string   absoluteFileName        = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5);

            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            var allAssemblies           = new Assembly[] { currentAssembly, siteMapProviderAssembly };
            var excludeTypes            = new Type[] {
                typeof(SiteMapNodeVisibilityProviderStrategy),
                typeof(SiteMapXmlReservedAttributeNameProvider),
                typeof(SiteMapBuilderSetStrategy),
                typeof(ControllerTypeResolverFactory)
            };
            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Single implementations of interface with matching name (minus the "I").
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => this.For(interfaceType).Singleton().Use(implementationType),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => this.For(interfaceType).Singleton().Use(implementationType),
                multipleImplementationTypes,
                allAssemblies,
                excludeTypes,
                "^Composite");

            // Visibility Providers
            this.For <ISiteMapNodeVisibilityProviderStrategy>().Use <SiteMapNodeVisibilityProviderStrategy>()
            .Ctor <string>("defaultProviderName").Is(string.Empty);

            // Pass in the global controllerBuilder reference
            this.For <ControllerBuilder>()
            .Use(x => ControllerBuilder.Current);

            this.For <IControllerBuilder>()
            .Use <ControllerBuilderAdaptor>();

            this.For <IBuildManager>()
            .Use <BuildManagerAdaptor>();

            this.For <IControllerTypeResolverFactory>().Use <ControllerTypeResolverFactory>()
            .Ctor <string[]>("areaNamespacesToIgnore").Is(new string[0]);

            // Configure Security
            this.For <IAclModule>().Use <CompositeAclModule>()
            .EnumerableOf <IAclModule>().Contains(x =>
            {
                x.Type <AuthorizeAttributeAclModule>();
                x.Type <XmlRolesAclModule>();
            });

            // Setup cache
            SmartInstance <CacheDetails> cacheDetails;

#if NET35
            this.For(typeof(ICacheProvider <>)).Use(typeof(AspNetCacheProvider <>));

            var cacheDependency =
                this.For <ICacheDependency>().Use <AspNetFileCacheDependency>()
                .Ctor <string>("fileName").Is(absoluteFileName);

            cacheDetails =
                this.For <ICacheDetails>().Use <CacheDetails>()
                .Ctor <TimeSpan>("absoluteCacheExpiration").Is(absoluteCacheExpiration)
                .Ctor <TimeSpan>("slidingCacheExpiration").Is(TimeSpan.MinValue)
                .Ctor <ICacheDependency>().Is(cacheDependency);
#else
            this.For <System.Runtime.Caching.ObjectCache>()
            .Use(s => System.Runtime.Caching.MemoryCache.Default);

            this.For(typeof(ICacheProvider <>)).Use(typeof(RuntimeCacheProvider <>));

            var cacheDependency =
                this.For <ICacheDependency>().Use <RuntimeFileCacheDependency>()
                .Ctor <string>("fileName").Is(absoluteFileName);

            cacheDetails =
                this.For <ICacheDetails>().Use <CacheDetails>()
                .Ctor <TimeSpan>("absoluteCacheExpiration").Is(absoluteCacheExpiration)
                .Ctor <TimeSpan>("slidingCacheExpiration").Is(TimeSpan.MinValue)
                .Ctor <ICacheDependency>().Is(cacheDependency);
#endif
            // Configure the visitors
            this.For <ISiteMapNodeVisitor>()
            .Use <UrlResolvingSiteMapNodeVisitor>();


            // Register the sitemap builder
            var xmlSource = this.For <IXmlSource>().Use <FileXmlSource>()
                            .Ctor <string>("fileName").Is(absoluteFileName);

            var reservedAttributeNameProvider = this.For <ISiteMapXmlReservedAttributeNameProvider>()
                                                .Use <SiteMapXmlReservedAttributeNameProvider>()
                                                .Ctor <IEnumerable <string> >("attributesToIgnore").Is(new string[0]);

            var builder = this.For <ISiteMapBuilder>().Use <CompositeSiteMapBuilder>()
                          .EnumerableOf <ISiteMapBuilder>().Contains(y =>
            {
                y.Type <XmlSiteMapBuilder>()
                .Ctor <ISiteMapXmlReservedAttributeNameProvider>().Is(reservedAttributeNameProvider)
                .Ctor <IXmlSource>().Is(xmlSource);
                y.Type <ReflectionSiteMapBuilder>()
                .Ctor <IEnumerable <string> >("includeAssemblies").Is(includeAssembliesForScan)
                .Ctor <IEnumerable <string> >("excludeAssemblies").Is(new string[0]);
                y.Type <VisitingSiteMapBuilder>();
            });


            // Configure the builder sets
            this.For <ISiteMapBuilderSetStrategy>().Use <SiteMapBuilderSetStrategy>()
            .EnumerableOf <ISiteMapBuilderSet>().Contains(x =>
            {
                x.Type <SiteMapBuilderSet>()
                .Ctor <string>("instanceName").Is("default")
                .Ctor <bool>("securityTrimmingEnabled").Is(securityTrimmingEnabled)
                .Ctor <bool>("enableLocalization").Is(enableLocalization)
                .Ctor <ISiteMapBuilder>().Is(builder)
                .Ctor <ICacheDetails>().Is(cacheDetails);
            });
        }
Пример #10
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            bool     enableLocalization               = true;
            string   absoluteFileName                 = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            bool     visibilityAffectsDescendants     = true;
            bool     useTitleIfDescriptionNotProvided = true;

#if Demo
            // Settings for MvcMusicStore demo: don't copy into your project
            bool     securityTrimmingEnabled  = true;
            string[] includeAssembliesForScan = new string[] { "Mvc Music Store" };
#else
            bool     securityTrimmingEnabled  = false;
            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };
#endif

            // Configure Windsor to resolve arrays in constructors
            container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel, true));

            var currentAssembly         = this.GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            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)
                typeof(SiteMapNodeUrlResolver)
            };
            var multipleImplementationTypes = new Type[]  {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };

            // Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
            // and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => container.Register(Component.For(interfaceType).ImplementedBy(implementationType).LifestyleSingleton()),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points (and not decorated with [ExcludeFromAutoRegistrationAttribute]).
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => container.Register(Component.For(interfaceType).ImplementedBy(implementationType).LifestyleSingleton()),
                multipleImplementationTypes,
                allAssemblies,
                new Type[0],
                string.Empty);

            // Registration of internal controllers
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => container.Register(Component.For(implementationType).ImplementedBy(implementationType).LifestyleTransient()),
                new Type[] { typeof(IController) },
                new Assembly[] { siteMapProviderAssembly },
                new Type[0],
                string.Empty);

            // Visibility Providers
            container.Register(Component.For <ISiteMapNodeVisibilityProviderStrategy>().ImplementedBy <SiteMapNodeVisibilityProviderStrategy>()
                               .DependsOn(Dependency.OnValue("defaultProviderName", string.Empty)));

            // Pass in the global controllerBuilder reference
            container.Register(Component.For <ControllerBuilder>().Instance(ControllerBuilder.Current));
            container.Register(Component.For <IControllerTypeResolverFactory>().ImplementedBy <ControllerTypeResolverFactory>()
                               .DependsOn(Dependency.OnValue("areaNamespacesToIgnore", new string[0])));

            // Configure Security

            // First registration wins - we must do the outer one first
            container.Register(Component.For <IAclModule>().ImplementedBy <CompositeAclModule>()
                               .DependsOn(Dependency.OnComponentCollection <IEnumerable <IAclModule> >(typeof(AuthorizeAttributeAclModule), typeof(XmlRolesAclModule))));

            container.Register(Component.For <IAclModule>().ImplementedBy <AuthorizeAttributeAclModule>());
            container.Register(Component.For <IAclModule>().ImplementedBy <XmlRolesAclModule>());


            // Setup cache
#if NET35
            container.Register(Component.For(typeof(ICacheProvider <>)).ImplementedBy(typeof(AspNetCacheProvider <>)));
            container.Register(Component.For <ICacheDependency>().ImplementedBy <AspNetFileCacheDependency>().Named("cacheDependency1")
                               .DependsOn(Dependency.OnValue("fileName", absoluteFileName)));
#else
            container.Register(Component.For <System.Runtime.Caching.ObjectCache>().Instance(System.Runtime.Caching.MemoryCache.Default));
            container.Register(Component.For(typeof(ICacheProvider <>)).ImplementedBy(typeof(RuntimeCacheProvider <>)));
            container.Register(Component.For <ICacheDependency>().ImplementedBy <RuntimeFileCacheDependency>().Named("cacheDependency1")
                               .DependsOn(Dependency.OnValue("fileName", absoluteFileName)));
#endif
            container.Register(Component.For <ICacheDetails>().ImplementedBy <CacheDetails>().Named("cacheDetails1")
                               .DependsOn(Dependency.OnValue("absoluteCacheExpiration", absoluteCacheExpiration))
                               .DependsOn(Dependency.OnValue("slidingCacheExpiration", TimeSpan.MinValue))
                               .DependsOn(ServiceOverride.ForKey <ICacheDependency>().Eq("cacheDependency1"))
                               );

            // Configure the visitors
            container.Register(Component.For <ISiteMapNodeVisitor>().ImplementedBy <UrlResolvingSiteMapNodeVisitor>());

            // Prepare for the sitemap node providers
            container.Register(Component.For <IXmlSource>().ImplementedBy <FileXmlSource>().Named("xmlSource1")
                               .DependsOn(Dependency.OnValue("fileName", absoluteFileName)));
            container.Register(Component.For <IReservedAttributeNameProvider>().ImplementedBy <ReservedAttributeNameProvider>()
                               .DependsOn(Dependency.OnValue("attributesToIgnore", new string[0])));

            // Register the sitemap node providers
            container.Register(Component.For <ISiteMapNodeProvider>().ImplementedBy <CompositeSiteMapNodeProvider>().Named("siteMapNodeProvider1")
                               .DependsOn(Dependency.OnComponentCollection <ISiteMapNodeProvider[]>("xmlSiteMapNodeProvider1", "reflectionSiteMapNodeProvider1")));

            container.Register(Component.For <ISiteMapNodeProvider>().ImplementedBy <XmlSiteMapNodeProvider>().Named("xmlSiteMapNodeProvider1")
                               .DependsOn(Dependency.OnValue("includeRootNode", true))
                               .DependsOn(Dependency.OnValue("useNestedDynamicNodeRecursion", false))
                               .DependsOn(ServiceOverride.ForKey <IXmlSource>().Eq("xmlSource1"))
                               );

            container.Register(Component.For <ISiteMapNodeProvider>().ImplementedBy <ReflectionSiteMapNodeProvider>().Named("reflectionSiteMapNodeProvider1")
                               .DependsOn(Dependency.OnValue("includeAssemblies", includeAssembliesForScan))
                               .DependsOn(Dependency.OnValue("excludeAssemblies", new string[0]))
                               );

            // Register the sitemap builders
            container.Register(Component.For <ISiteMapBuilder>().ImplementedBy <SiteMapBuilder>().Named("builder1")
                               .DependsOn(ServiceOverride.ForKey <ISiteMapNodeProvider>().Eq("siteMapNodeProvider1"))
                               );

            // Configure the builder sets
            container.Register(Component.For <ISiteMapBuilderSet>().ImplementedBy <SiteMapBuilderSet>().Named("siteMapBuilderSet1")
                               .DependsOn(Dependency.OnValue("instanceName", "default"))
                               .DependsOn(Dependency.OnValue("securityTrimmingEnabled", securityTrimmingEnabled))
                               .DependsOn(Dependency.OnValue("enableLocalization", enableLocalization))
                               .DependsOn(Dependency.OnValue("visibilityAffectsDescendants", visibilityAffectsDescendants))
                               .DependsOn(Dependency.OnValue("useTitleIfDescriptionNotProvided", useTitleIfDescriptionNotProvided))
                               .DependsOn(ServiceOverride.ForKey <ISiteMapBuilder>().Eq("builder1"))
                               .DependsOn(ServiceOverride.ForKey <ICacheDetails>().Eq("cacheDetails1"))
                               );

            container.Register(Component.For <ISiteMapBuilderSetStrategy>().ImplementedBy <SiteMapBuilderSetStrategy>()
                               .DependsOn(Dependency.OnComponentCollection <ISiteMapBuilderSet[]>("siteMapBuilderSet1")));
        }
Пример #11
0
    protected override void Initialize()
    {
        bool securityTrimmingEnabled = false;
        bool enableLocalization      = true;

        string rootSiteMapFile  = HostingEnvironment.MapPath("~/Mvc.sitemap");
        string adminSiteMapFile = HostingEnvironment.MapPath("~/Areas/Admin/Mvc.sitemap");

        TimeSpan absoluteCacheExpiration = TimeSpan.FromMinutes(5);

        string[] includeAssembliesForScan = new string[] { "MccSiteMapProviderTest" };

        var currentAssembly         = this.GetType().Assembly;
        var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
        var allAssemblies           = new Assembly[] { currentAssembly, siteMapProviderAssembly };
        var excludeTypes            = new Type[] {
            typeof(SiteMapNodeVisibilityProviderStrategy),
            typeof(SiteMapXmlReservedAttributeNameProvider),
            typeof(SiteMapBuilderSetStrategy),
            typeof(SiteMapNodeUrlResolverStrategy),
            typeof(DynamicNodeProviderStrategy)
        };
        var multipleImplementationTypes = new Type[] {
            typeof(ISiteMapNodeUrlResolver),
            typeof(ISiteMapNodeVisibilityProvider),
            typeof(IDynamicNodeProvider)
        };

        // Single implementations of interface with matching name (minus the "I").
        CommonConventions.RegisterDefaultConventions(
            (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, new ContainerControlledLifetimeManager()),
            new Assembly[] { siteMapProviderAssembly },
            allAssemblies,
            excludeTypes,
            string.Empty);

        // Multiple implementations of strategy based extension points
        CommonConventions.RegisterAllImplementationsOfInterface(
            (interfaceType, implementationType) => this.Container.RegisterType(interfaceType, implementationType, implementationType.Name, new ContainerControlledLifetimeManager()),
            multipleImplementationTypes,
            allAssemblies,
            excludeTypes,
            "^Composite");

        // TODO: Find a better way to inject an array constructor

        // Url Resolvers
        this.Container.RegisterType <ISiteMapNodeUrlResolverStrategy, SiteMapNodeUrlResolverStrategy>(new InjectionConstructor(
                                                                                                          new ResolvedArrayParameter <ISiteMapNodeUrlResolver>(this.Container.ResolveAll <ISiteMapNodeUrlResolver>().ToArray())
                                                                                                          ));

        // Visibility Providers
        this.Container.RegisterType <ISiteMapNodeVisibilityProviderStrategy, SiteMapNodeVisibilityProviderStrategy>(new InjectionConstructor(
                                                                                                                        new ResolvedArrayParameter <ISiteMapNodeVisibilityProvider>(this.Container.ResolveAll <ISiteMapNodeVisibilityProvider>().ToArray()),
                                                                                                                        new InjectionParameter <string>(string.Empty)
                                                                                                                        ));

        // Dynamic Node Providers
        this.Container.RegisterType <IDynamicNodeProviderStrategy, DynamicNodeProviderStrategy>(new InjectionConstructor(
                                                                                                    new ResolvedArrayParameter <IDynamicNodeProvider>(this.Container.ResolveAll <IDynamicNodeProvider>().ToArray())
                                                                                                    ));


        // Pass in the global controllerBuilder reference
        this.Container.RegisterInstance <ControllerBuilder>(ControllerBuilder.Current);
        this.Container.RegisterType <IControllerBuilder, ControllerBuilderAdaptor>(new PerResolveLifetimeManager());

        this.Container.RegisterType <IBuildManager, BuildManagerAdaptor>(new PerResolveLifetimeManager());

        this.Container.RegisterType <IControllerTypeResolverFactory, ControllerTypeResolverFactory>(new InjectionConstructor(
                                                                                                        new List <string>(),
                                                                                                        new ResolvedParameter <IControllerBuilder>(),
                                                                                                        new ResolvedParameter <IBuildManager>()));

        // Configure Security

        // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
        // Register the sitemap node providers
        this.Container.RegisterInstance <ISiteMapNodeProvider>("rootXmlSiteMapNodeProvider",
                                                               this.Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(this.Container.Resolve <IXmlSource>("rootSiteMapXmlSource")), new ContainerControlledLifetimeManager());

        this.Container.RegisterInstance <ISiteMapNodeProvider>("adminXmlSiteMapNodeProvider",
                                                               this.Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(this.Container.Resolve <IXmlSource>("adminSiteMapXmlSource")), new ContainerControlledLifetimeManager());

        this.Container.RegisterInstance <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1",
                                                               this.Container.Resolve <ReflectionSiteMapNodeProviderFactory>().Create(includeAssembliesForScan), new ContainerControlledLifetimeManager());
        this.Container.RegisterType <ISiteMapNodeProvider, CompositeSiteMapNodeProvider>(new InjectionConstructor(new ResolvedArrayParameter <ISiteMapNodeProvider>(
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("rootXmlSiteMapNodeProvider"),
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("adminXmlSiteMapNodeProvider"),
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1"))));

        // Configure the builders
        this.Container.RegisterType <ISiteMapBuilder, SiteMapBuilder>();

        // Configure the builder sets
        this.Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("rootBuilderSet",
                                                                            new InjectionConstructor(
                                                                                "default",
                                                                                securityTrimmingEnabled,
                                                                                enableLocalization,
                                                                                new ResolvedParameter <ISiteMapBuilder>(), // You are sharing the same builder instance here
                                                                                new ResolvedParameter <ICacheDetails>("rootSiteMapCacheDetails")));

        this.Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("adminBuilderSet",
                                                                            new InjectionConstructor(
                                                                                "admin",
                                                                                securityTrimmingEnabled,
                                                                                enableLocalization,
                                                                                new ResolvedParameter <ISiteMapBuilder>(), // You are sharing the same builder instance here
                                                                                new ResolvedParameter <ICacheDetails>("adminSiteMapCacheDetails")));


        Instead of the above, it should be something like...

        // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
        // Register the sitemap node providers
        this.Container.RegisterInstance <ISiteMapNodeProvider>("rootXmlSiteMapNodeProvider",
                                                               this.Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(this.Container.Resolve <IXmlSource>("rootSiteMapXmlSource")), new ContainerControlledLifetimeManager());

        this.Container.RegisterInstance <ISiteMapNodeProvider>("adminXmlSiteMapNodeProvider",
                                                               this.Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(this.Container.Resolve <IXmlSource>("adminSiteMapXmlSource")), new ContainerControlledLifetimeManager());

        this.Container.RegisterInstance <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1",
                                                               this.Container.Resolve <ReflectionSiteMapNodeProviderFactory>().Create(includeAssembliesForScan), new ContainerControlledLifetimeManager());

        this.Container.RegisterType <ISiteMapNodeProvider, CompositeSiteMapNodeProvider>("rootSiteMapNodeProvider",
                                                                                         new ContainerControlledLifetimeManager(),
                                                                                         new InjectionConstructor(new ResolvedArrayParameter <ISiteMapNodeProvider>(
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("rootXmlSiteMapNodeProvider"),
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1"))));

        this.Container.RegisterType <ISiteMapNodeProvider, CompositeSiteMapNodeProvider>("adminSiteMapNodeProvider",
                                                                                         new ContainerControlledLifetimeManager(),
                                                                                         new InjectionConstructor(new ResolvedArrayParameter <ISiteMapNodeProvider>(
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("adminXmlSiteMapNodeProvider"),
                                                                                                                      new ResolvedParameter <ISiteMapNodeProvider>("ReflectionSiteMapNodeProvider1"))));

        // Configure the builders
        this.Container.RegisterInstance <ISiteMapBuilder>("rootSiteMapBuilder",
                                                          this.Container.Resolve <SiteMapBuilderFactory>().Create(this.Container.Resolve <ISiteMapNodeProvider>("rootSiteMapNodeProvider")),
                                                          new ContainerControlledLifetimeManager());

        this.Container.RegisterInstance <ISiteMapBuilder>("adminSiteMapBuilder",
                                                          this.Container.Resolve <SiteMapBuilderFactory>().Create(this.Container.Resolve <ISiteMapNodeProvider>("adminSiteMapNodeProvider")),
                                                          new ContainerControlledLifetimeManager());

        // Configure the builder sets
        this.Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("rootBuilderSet",
                                                                            new InjectionConstructor(
                                                                                "default",
                                                                                securityTrimmingEnabled,
                                                                                enableLocalization,
                                                                                new ResolvedParameter <ISiteMapBuilder>("rootSiteMapBuilder"),
                                                                                new ResolvedParameter <ICacheDetails>("rootSiteMapCacheDetails")));

        this.Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("adminBuilderSet",
                                                                            new InjectionConstructor(
                                                                                "admin",
                                                                                securityTrimmingEnabled,
                                                                                enableLocalization,
                                                                                new ResolvedParameter <ISiteMapBuilder>("adminSiteMapBuilder"),
                                                                                new ResolvedParameter <ICacheDetails>("adminSiteMapCacheDetails")));
    }
        protected override void Initialize()
        {
            const bool enableLocalization               = true;
            string     absoluteFileName                 = HostingEnvironment.MapPath("~/Store.sitemap");
            TimeSpan   absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            const bool visibilityAffectsDescendants     = true;
            const bool useTitleIfDescriptionNotProvided = true;

            const bool securityTrimmingEnabled  = false;
            var        includeAssembliesForScan = new[] { "VirtoCommerce.Web" };

            var currentAssembly         = GetType().Assembly;
            var siteMapProviderAssembly = typeof(SiteMaps).Assembly;
            var clientAssembly          = typeof(NamedSiteMapNodeVisibilityProvider).Assembly;
            var allAssemblies           = new[] { currentAssembly, siteMapProviderAssembly, clientAssembly };
            var excludeTypes            = new[] {
                typeof(IRouteValueDictionaryFactory),
                typeof(ISiteMapCacheKeyGenerator),
            };
            var multipleImplementationTypes = new[] {
                typeof(ISiteMapNodeUrlResolver),
                typeof(ISiteMapNodeVisibilityProvider),
                typeof(IDynamicNodeProvider)
            };



// Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
// and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => Container.RegisterType(interfaceType, implementationType, new ContainerControlledLifetimeManager()),
                new[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

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

// TODO: Find a better way to inject an array constructor

//Register custom route value dictionary factory
            Container.RegisterType <IRouteValueDictionaryFactory, SeoRouteValueDictionaryFactory>(new InjectionConstructor(
                                                                                                      new ResolvedParameter <IRequestCache>(),
                                                                                                      new ResolvedParameter <IReservedAttributeNameProvider>(),
                                                                                                      new ResolvedParameter <IJsonToDictionaryDeserializer>()));

//Register custom sitemap cache key generator
            Container.RegisterType <ISiteMapCacheKeyGenerator, SiteMapStoreCacheKeyGenerator>(new InjectionConstructor(
                                                                                                  new ResolvedParameter <IMvcContextFactory>()));

// Url Resolvers
            Container.RegisterType <ISiteMapNodeUrlResolverStrategy, SiteMapNodeUrlResolverStrategy>(new InjectionConstructor(
                                                                                                         new ResolvedArrayParameter <ISiteMapNodeUrlResolver>(Container.ResolveAll <ISiteMapNodeUrlResolver>().ToArray())
                                                                                                         ));

// Visibility Providers
            Container.RegisterType <ISiteMapNodeVisibilityProviderStrategy, SiteMapNodeVisibilityProviderStrategy>(new InjectionConstructor(
                                                                                                                       new ResolvedArrayParameter <ISiteMapNodeVisibilityProvider>(Container.ResolveAll <ISiteMapNodeVisibilityProvider>().ToArray()),
                                                                                                                       new InjectionParameter <string>(typeof(NamedSiteMapNodeVisibilityProvider).ShortAssemblyQualifiedName())
                                                                                                                       ));

// Dynamic Node Providers
            Container.RegisterType <IDynamicNodeProviderStrategy, DynamicNodeProviderStrategy>(new InjectionConstructor(
                                                                                                   new ResolvedArrayParameter <IDynamicNodeProvider>(Container.ResolveAll <IDynamicNodeProvider>().ToArray())
                                                                                                   ));


// Pass in the global controllerBuilder reference
            Container.RegisterInstance <ControllerBuilder>(ControllerBuilder.Current);

            Container.RegisterType <IControllerTypeResolverFactory, ControllerTypeResolverFactory>(new InjectionConstructor(
                                                                                                       new List <string>(),
                                                                                                       new ResolvedParameter <IControllerBuilder>(),
                                                                                                       new ResolvedParameter <IBuildManager>()));

// Configure Security

// IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
            Container.RegisterType <IAclModule, AuthorizeAttributeAclModule>("authorizeAttribute");
            Container.RegisterType <IAclModule, XmlRolesAclModule>("xmlRoles");
            Container.RegisterType <IAclModule, CompositeAclModule>(new InjectionConstructor(new ResolvedArrayParameter <IAclModule>(
                                                                                                 new ResolvedParameter <IAclModule>("authorizeAttribute"),
                                                                                                 new ResolvedParameter <IAclModule>("xmlRoles"))));

            Container.RegisterInstance <ObjectCache>(MemoryCache.Default);
            Container.RegisterType(typeof(ICacheProvider <>), typeof(RuntimeCacheProvider <>));
            Container.RegisterType <ICacheDependency, RuntimeFileCacheDependency>(
                "cacheDependency", new InjectionConstructor(absoluteFileName));

            Container.RegisterType <ICacheDetails, CacheDetails>("cacheDetails",
                                                                 new InjectionConstructor(absoluteCacheExpiration, TimeSpan.MinValue, new ResolvedParameter <ICacheDependency>("cacheDependency")));

// Configure the visitors
            Container.RegisterType <ISiteMapNodeVisitor, UrlResolvingSiteMapNodeVisitor>();

// Prepare for the sitemap node providers
            Container.RegisterType <IXmlSource, FileXmlSource>("file1XmlSource", new InjectionConstructor(absoluteFileName));
            Container.RegisterType <IReservedAttributeNameProvider, ReservedAttributeNameProvider>(new InjectionConstructor(new List <string>()));

// IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them.
// Register the sitemap node providers
            Container.RegisterInstance <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1",
                                                              Container.Resolve <XmlSiteMapNodeProviderFactory>().Create(Container.Resolve <IXmlSource>("file1XmlSource")), new ContainerControlledLifetimeManager());
            Container.RegisterInstance <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1",
                                                              Container.Resolve <ReflectionSiteMapNodeProviderFactory>().Create(includeAssembliesForScan), new ContainerControlledLifetimeManager());
            Container.RegisterType <ISiteMapNodeProvider, CompositeSiteMapNodeProvider>(new InjectionConstructor(new ResolvedArrayParameter <ISiteMapNodeProvider>(
                                                                                                                     new ResolvedParameter <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                                                                                                                     new ResolvedParameter <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1"))));

// Configure the builders
            Container.RegisterType <ISiteMapBuilder, SiteMapBuilder>();

// Configure the builder sets
            Container.RegisterType <ISiteMapBuilderSet, SiteMapBuilderSet>("builderSet1",
                                                                           new InjectionConstructor(
                                                                               "default",
                                                                               securityTrimmingEnabled,
                                                                               enableLocalization,
                                                                               visibilityAffectsDescendants,
                                                                               useTitleIfDescriptionNotProvided,
                                                                               new ResolvedParameter <ISiteMapBuilder>(),
                                                                               new ResolvedParameter <ICacheDetails>("cacheDetails")));

            Container.RegisterType <ISiteMapBuilderSetStrategy, SiteMapBuilderSetStrategy>(new InjectionConstructor(
                                                                                               new ResolvedArrayParameter <ISiteMapBuilderSet>(new ResolvedParameter <ISiteMapBuilderSet>("builderSet1"))));
        }
        public override void Load()
        {
            bool     enableLocalization               = true;
            string   absoluteFileName                 = HostingEnvironment.MapPath("~/Mvc.sitemap");
            TimeSpan absoluteCacheExpiration          = TimeSpan.FromMinutes(5);
            bool     visibilityAffectsDescendants     = true;
            bool     useTitleIfDescriptionNotProvided = true;

#if Demo
            // Settings for MvcMusicStore demo: don't copy into your project
            bool     securityTrimmingEnabled  = true;
            string[] includeAssembliesForScan = new string[] { "Mvc Music Store" };
#else
            bool     securityTrimmingEnabled  = false;
            string[] includeAssembliesForScan = new string[] { "$AssemblyName$" };
#endif

            var currentAssembly             = this.GetType().Assembly;
            var siteMapProviderAssembly     = typeof(SiteMaps).Assembly;
            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),
                typeof(IDynamicNodeProvider)
            };

            // Matching type name (I[TypeName] = [TypeName]) or matching type name + suffix Adapter (I[TypeName] = [TypeName]Adapter)
            // and not decorated with the [ExcludeFromAutoRegistrationAttribute].
            CommonConventions.RegisterDefaultConventions(
                (interfaceType, implementationType) => this.Kernel.Bind(interfaceType).To(implementationType).InSingletonScope(),
                new Assembly[] { siteMapProviderAssembly },
                allAssemblies,
                excludeTypes,
                string.Empty);

            // Multiple implementations of strategy based extension points (and not decorated with [ExcludeFromAutoRegistrationAttribute]).
            CommonConventions.RegisterAllImplementationsOfInterface(
                (interfaceType, implementationType) => this.Kernel.Bind(interfaceType).To(implementationType).InSingletonScope(),
                multipleImplementationTypes,
                allAssemblies,
                excludeTypes,
                string.Empty);

            this.Kernel.Bind <ISiteMapNodeVisibilityProviderStrategy>().To <SiteMapNodeVisibilityProviderStrategy>()
            .WithConstructorArgument("defaultProviderName", string.Empty);

            this.Kernel.Bind <ControllerBuilder>().ToConstant(ControllerBuilder.Current);

            this.Kernel.Bind <IControllerTypeResolverFactory>().To <ControllerTypeResolverFactory>()
            .WithConstructorArgument("areaNamespacesToIgnore", new string[0]);

            // Configure Security
            this.Kernel.Bind <AuthorizeAttributeAclModule>().ToSelf();
            this.Kernel.Bind <XmlRolesAclModule>().ToSelf();
            this.Kernel.Bind <IAclModule>().To <CompositeAclModule>()
            .WithConstructorArgument("aclModules",
                                     new IAclModule[] {
                this.Kernel.Get <AuthorizeAttributeAclModule>(),
                this.Kernel.Get <XmlRolesAclModule>()
            });


            // Setup cache
#if NET35
            this.Kernel.Bind(typeof(ICacheProvider <>)).To(typeof(AspNetCacheProvider <>));
            this.Kernel.Bind <ICacheDependency>().To <AspNetFileCacheDependency>().Named("cacheDependency1")
            .WithConstructorArgument("fileName", absoluteFileName);
#else
            this.Kernel.Bind <System.Runtime.Caching.ObjectCache>()
            .ToConstant <System.Runtime.Caching.ObjectCache>(System.Runtime.Caching.MemoryCache.Default);
            this.Kernel.Bind(typeof(ICacheProvider <>)).To(typeof(RuntimeCacheProvider <>));
            this.Kernel.Bind <ICacheDependency>().To <RuntimeFileCacheDependency>().Named("cacheDependency1")
            .WithConstructorArgument("fileName", absoluteFileName);
#endif
            this.Kernel.Bind <ICacheDetails>().To <CacheDetails>().Named("cacheDetails1")
            .WithConstructorArgument("absoluteCacheExpiration", absoluteCacheExpiration)
            .WithConstructorArgument("slidingCacheExpiration", TimeSpan.MinValue)
            .WithConstructorArgument("cacheDependency", this.Kernel.Get <ICacheDependency>("cacheDependency1"));


            // Configure the visitors
            this.Kernel.Bind <ISiteMapNodeVisitor>().To <UrlResolvingSiteMapNodeVisitor>();

            // Prepare for our node providers
            this.Kernel.Bind <IXmlSource>().To <FileXmlSource>().Named("XmlSource1")
            .WithConstructorArgument("fileName", absoluteFileName);
            this.Kernel.Bind <IReservedAttributeNameProvider>().To <ReservedAttributeNameProvider>()
            .WithConstructorArgument("attributesToIgnore", new string[0]);

            // Register the sitemap node providers
            this.Kernel.Bind <ISiteMapNodeProvider>().To <XmlSiteMapNodeProvider>().Named("xmlSiteMapNodeProvider1")
            .WithConstructorArgument("includeRootNode", true)
            .WithConstructorArgument("useNestedDynamicNodeRecursion", false)
            .WithConstructorArgument("xmlSource", this.Kernel.Get <IXmlSource>("XmlSource1"));

            this.Kernel.Bind <ISiteMapNodeProvider>().To <ReflectionSiteMapNodeProvider>().Named("reflectionSiteMapNodeProvider1")
            .WithConstructorArgument("includeAssemblies", includeAssembliesForScan)
            .WithConstructorArgument("excludeAssemblies", new string[0]);

            this.Kernel.Bind <ISiteMapNodeProvider>().To <CompositeSiteMapNodeProvider>().Named("siteMapNodeProvider1")
            .WithConstructorArgument("siteMapNodeProviders",
                                     new ISiteMapNodeProvider[] {
                this.Kernel.Get <ISiteMapNodeProvider>("xmlSiteMapNodeProvider1"),
                this.Kernel.Get <ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
            });

            // Register the sitemap builders
            this.Kernel.Bind <ISiteMapBuilder>().To <SiteMapBuilder>().Named("siteMapBuilder1")
            .WithConstructorArgument("siteMapNodeProvider", this.Kernel.Get <ISiteMapNodeProvider>("siteMapNodeProvider1"));

            // Configure the builder sets
            this.Kernel.Bind <ISiteMapBuilderSet>().To <SiteMapBuilderSet>().Named("siteMapBuilderSet1")
            .WithConstructorArgument("instanceName", "default")
            .WithConstructorArgument("securityTrimmingEnabled", securityTrimmingEnabled)
            .WithConstructorArgument("enableLocalization", enableLocalization)
            .WithConstructorArgument("visibilityAffectsDescendants", visibilityAffectsDescendants)
            .WithConstructorArgument("useTitleIfDescriptionNotProvided", useTitleIfDescriptionNotProvided)
            .WithConstructorArgument("siteMapBuilder", this.Kernel.Get <ISiteMapBuilder>("siteMapBuilder1"))
            .WithConstructorArgument("cacheDetails", this.Kernel.Get <ICacheDetails>("cacheDetails1"));

            this.Kernel.Bind <ISiteMapBuilderSetStrategy>().To <SiteMapBuilderSetStrategy>()
            .WithConstructorArgument("siteMapBuilderSets",
                                     new ISiteMapBuilderSet[] {
                this.Kernel.Get <ISiteMapBuilderSet>("siteMapBuilderSet1")
            });
        }