From 3b7638a14fb6a6e8d7226f1f652bd354f8400184 Mon Sep 17 00:00:00 2001 From: Shad Storhaug Date: Mon, 12 Oct 2015 02:25:48 +0700 Subject: [PATCH] Fixes #409, changed Unity MvcSiteMapProviderContainerExtension to produce instances at runtime instead of at composition time. Also removed the references to the XmlSiteMapNodeProviderFactory and ReflectionSiteMapNodeProviderFactory, since it is better to have the container resolve the instances (the factories were created because no alternative was known at the time). --- .../MvcSiteMapProviderContainerExtension.cs | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/MvcSiteMapProvider/CodeAsConfiguration/Unity/DI/Unity/ContainerExtensions/MvcSiteMapProviderContainerExtension.cs b/src/MvcSiteMapProvider/CodeAsConfiguration/Unity/DI/Unity/ContainerExtensions/MvcSiteMapProviderContainerExtension.cs index acb21c1a..3b294806 100644 --- a/src/MvcSiteMapProvider/CodeAsConfiguration/Unity/DI/Unity/ContainerExtensions/MvcSiteMapProviderContainerExtension.cs +++ b/src/MvcSiteMapProvider/CodeAsConfiguration/Unity/DI/Unity/ContainerExtensions/MvcSiteMapProviderContainerExtension.cs @@ -1,9 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Reflection; -using System.Web.Mvc; using System.Web.Hosting; +using System.Web.Mvc; using Microsoft.Practices.Unity; using MvcSiteMapProvider; using MvcSiteMapProvider.Builder; @@ -77,22 +76,20 @@ protected override void Initialize() excludeTypes, string.Empty); - // TODO: Find a better way to inject an array constructor - // Url Resolvers this.Container.RegisterType(new InjectionConstructor( - new ResolvedArrayParameter(this.Container.ResolveAll().ToArray()) + new ResolvedParameter() )); // Visibility Providers this.Container.RegisterType(new InjectionConstructor( - new ResolvedArrayParameter(this.Container.ResolveAll().ToArray()), - new InjectionParameter(string.Empty) + new ResolvedParameter(), + new InjectionParameter(string.Empty) // defaultProviderName )); // Dynamic Node Providers this.Container.RegisterType(new InjectionConstructor( - new ResolvedArrayParameter(this.Container.ResolveAll().ToArray()) + new ResolvedParameter() )); @@ -109,19 +106,19 @@ protected override void Initialize() // IMPORTANT: Must give arrays of object a name in Unity in order for it to resolve them. this.Container.RegisterType("authorizeAttribute"); this.Container.RegisterType("xmlRoles"); - this.Container.RegisterType(new InjectionConstructor(new ResolvedArrayParameter( - new ResolvedParameter("authorizeAttribute"), - new ResolvedParameter("xmlRoles")))); + this.Container.RegisterType(new InjectionConstructor( + new ResolvedParameter() + )); #if NET35 this.Container.RegisterType(typeof(ICacheProvider<>), typeof(AspNetCacheProvider<>)); this.Container.RegisterType( - "cacheDependency", new InjectionConstructor(absoluteFileName)); + "cacheDependency", new InjectionConstructor(new InjectionParameter(absoluteFileName))); #else this.Container.RegisterInstance(System.Runtime.Caching.MemoryCache.Default); this.Container.RegisterType(typeof(ICacheProvider<>), typeof(RuntimeCacheProvider<>)); this.Container.RegisterType( - "cacheDependency", new InjectionConstructor(absoluteFileName)); + "cacheDependency", new InjectionConstructor(new InjectionParameter(absoluteFileName))); #endif this.Container.RegisterType("cacheDetails", new InjectionConstructor(absoluteCacheExpiration, TimeSpan.MinValue, new ResolvedParameter("cacheDependency"))); @@ -130,15 +127,26 @@ protected override void Initialize() this.Container.RegisterType(); // Prepare for the sitemap node providers - this.Container.RegisterType("file1XmlSource", new InjectionConstructor(absoluteFileName)); + this.Container.RegisterType("file1XmlSource", new InjectionConstructor(new InjectionParameter(absoluteFileName))); this.Container.RegisterType(new InjectionConstructor(new List())); // 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("xmlSiteMapNodeProvider1", - this.Container.Resolve().Create(this.Container.Resolve("file1XmlSource")), new ContainerControlledLifetimeManager()); - this.Container.RegisterInstance("reflectionSiteMapNodeProvider1", - this.Container.Resolve().Create(includeAssembliesForScan), new ContainerControlledLifetimeManager()); + this.Container.RegisterType( + "xmlSiteMapNodeProvider1", + new ContainerControlledLifetimeManager(), + new InjectionFactory(c => c.Resolve( + new ParameterOverride("includeRootNode", true), + new ParameterOverride("useNestedDynamicNodeRecursion", false), + new DependencyOverride(c.Resolve("file1XmlSource")) + ))); + this.Container.RegisterType( + "reflectionSiteMapNodeProvider1", + new ContainerControlledLifetimeManager(), + new InjectionFactory(c => c.Resolve( + new ParameterOverride("includeAssemblies", includeAssembliesForScan), + new ParameterOverride("excludeAssemblies", new string[0]) + ))); this.Container.RegisterType(new InjectionConstructor(new ResolvedArrayParameter( new ResolvedParameter("xmlSiteMapNodeProvider1"), new ResolvedParameter("reflectionSiteMapNodeProvider1"))));