Skip to content

Commit

Permalink
Updated the external DI container configurations to use the new ISite…
Browse files Browse the repository at this point in the history
…MapNodeProvider model.
  • Loading branch information
NightOwl888 committed Sep 11, 2013
1 parent 74313f4 commit 425c15c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<UrlResolvingSiteMapNodeVisitor>()
.As<ISiteMapNodeVisitor>();

// Prepare for our builders
// Prepare for our node providers
builder.RegisterType<FileXmlSource>()
.Named<IXmlSource>("xmlSource1")
.WithParameter("fileName", absoluteFileName);
Expand All @@ -144,32 +144,38 @@ protected override void Load(ContainerBuilder builder)
.As<ISiteMapXmlReservedAttributeNameProvider>()
.WithParameter("attributesToIgnore", new string[0]);

// Register the sitemap builders
builder.RegisterType<XmlSiteMapBuilder>()
.Named<ISiteMapBuilder>("xmlSiteMapBuilder1")

// 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<ReflectionSiteMapBuilder>()
.Named<ISiteMapBuilder>("reflectionSiteMapBuilder1")
builder.RegisterType<ReflectionSiteMapNodeProvider>()
.Named<ISiteMapNodeProvider>("reflectionSiteMapNodeProvider1")
.WithParameter("includeAssemblies", includeAssembliesForScan)
.WithParameter("excludeAssemblies", new string[0]);

builder.RegisterType<VisitingSiteMapBuilder>()
.Named<ISiteMapBuilder>("visitingSiteMapBuilder1");

builder.RegisterType<CompositeSiteMapBuilder>()
.Named<ISiteMapBuilder>("siteMapBuilder1")
builder.RegisterType<CompositeSiteMapNodeProvider>()
.Named<ISiteMapNodeProvider>("siteMapNodeProvider1")
.WithParameter(
(p, c) => p.Name == "siteMapBuilders",
(p, c) => p.Name == "siteMapNodeProviders",
(p, c) => new[]
{
c.ResolveNamed<ISiteMapBuilder>("xmlSiteMapBuilder1"),
c.ResolveNamed<ISiteMapBuilder>("reflectionSiteMapBuilder1"),
c.ResolveNamed<ISiteMapBuilder>("visitingSiteMapBuilder1")
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,44 +102,39 @@ public override void Load()
// Configure the visitors
this.Kernel.Bind<ISiteMapNodeVisitor>().To<UrlResolvingSiteMapNodeVisitor>();

// Register the sitemap builder
this.Kernel.Bind<IXmlSource>().To<FileXmlSource>().Named("xmlBuilderXmlSource")
// 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]);

// Xml Builder
this.Kernel.Bind<ISiteMapBuilder>().To<XmlSiteMapBuilder>().Named("xmlSiteMapBuilder")
.WithConstructorArgument("reservedAttributeNameProvider", this.Kernel.Get<ISiteMapXmlReservedAttributeNameProvider>("xmlBuilderReservedAttributeNameProvider"))
.WithConstructorArgument("xmlSource", this.Kernel.Get<IXmlSource>("xmlBuilderXmlSource"));
// 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"));



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

// Visiting Builder
this.Kernel.Bind<ISiteMapBuilder>().To<VisitingSiteMapBuilder>().Named("visitingSiteMapBuilder");


// Composite builder
this.Kernel.Bind<ISiteMapBuilder>().To<CompositeSiteMapBuilder>().Named("compositeSiteMapBuilder")
.WithConstructorArgument("siteMapBuilders",
new ISiteMapBuilder[] {
this.Kernel.Get<ISiteMapBuilder>("xmlSiteMapBuilder"),
this.Kernel.Get<ISiteMapBuilder>("reflectionSiteMapBuilder"),
this.Kernel.Get<ISiteMapBuilder>("visitingSiteMapBuilder")
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>("compositeSiteMapBuilder"))
.WithConstructorArgument("siteMapBuilder", this.Kernel.Get<ISiteMapBuilder>("siteMapBuilder1"))
.WithConstructorArgument("cacheDetails", this.Kernel.Get<ICacheDetails>("cacheDetails1"));

this.Kernel.Bind<ISiteMapBuilderSetStrategy>().To<SiteMapBuilderSetStrategy>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,39 +127,25 @@ public static void SetUp(Container container)
container.RegisterSingle<ISiteMapNodeVisitor, UrlResolvingSiteMapNodeVisitor>();


// Register the sitemap builder
// Prepare for the sitemap node providers
container.RegisterSingle<ISiteMapXmlReservedAttributeNameProvider>(
() => new SiteMapXmlReservedAttributeNameProvider(new string[0]));

container.RegisterSingle<IXmlSource>(() => new FileXmlSource(absoluteFileName));


container.RegisterSingle<XmlSiteMapBuilder>(() =>
new XmlSiteMapBuilder(
container.GetInstance<IXmlSource>(),
container.GetInstance<ISiteMapXmlReservedAttributeNameProvider>(),
container.GetInstance<INodeKeyGenerator>(),
container.GetInstance<IDynamicNodeBuilder>(),
container.GetInstance<ISiteMapNodeFactory>(),
container.GetInstance<ISiteMapXmlNameProvider>()
));

container.RegisterSingle<ReflectionSiteMapBuilder>(() =>
new ReflectionSiteMapBuilder(
includeAssembliesForScan,
new string[0],
container.GetInstance
<ISiteMapXmlReservedAttributeNameProvider>(),
container.GetInstance<INodeKeyGenerator>(),
container.GetInstance<IDynamicNodeBuilder>(),
container.GetInstance<ISiteMapNodeFactory>(),
container.GetInstance<ISiteMapCacheKeyGenerator>()
));
// Register the sitemap node providers
container.RegisterSingle<XmlSiteMapNodeProvider>(() => container.GetInstance<XmlSiteMapNodeProviderFactory>()
.Create(container.GetInstance<IXmlSource>()));
container.RegisterSingle<ReflectionSiteMapNodeProvider>(() => container.GetInstance<ReflectionSiteMapNodeProviderFactory>()
.Create(includeAssembliesForScan));

// Register the sitemap builders
container.RegisterSingle<ISiteMapBuilder>(() => container.GetInstance<SiteMapBuilderFactory>()
.Create(new CompositeSiteMapNodeProvider(container.GetInstance<XmlSiteMapNodeProvider>(), container.GetInstance<ReflectionSiteMapNodeProvider>())));

container.RegisterAll<ISiteMapBuilderSet>(ResolveISiteMapBuilderSets(container, securityTrimmingEnabled, enableLocalization));
container.RegisterSingle<ISiteMapBuilderSetStrategy>(() => new SiteMapBuilderSetStrategy(container.GetAllInstances<ISiteMapBuilderSet>().ToArray()));

container.RegisterSingle<VisitingSiteMapBuilder>();
}

private static IEnumerable<ISiteMapBuilderSet> ResolveISiteMapBuilderSets(Container container, bool securityTrimmingEnabled, bool enableLocalization)
Expand All @@ -168,10 +154,7 @@ private static IEnumerable<ISiteMapBuilderSet> ResolveISiteMapBuilderSets(Contai
"default",
securityTrimmingEnabled,
enableLocalization,
new CompositeSiteMapBuilder(
container.GetInstance<XmlSiteMapBuilder>(),
container.GetInstance<ReflectionSiteMapBuilder>(),
container.GetInstance<VisitingSiteMapBuilder>()),
container.GetInstance<ISiteMapBuilder>(),
container.GetInstance<ICacheDetails>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,29 @@ public MvcSiteMapProviderRegistry()
.Use<UrlResolvingSiteMapNodeVisitor>();


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

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

var builder = this.For<ISiteMapBuilder>().Use<CompositeSiteMapBuilder>()
.EnumerableOf<ISiteMapBuilder>().Contains(y =>

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

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

// Configure the builder sets
this.For<ISiteMapBuilderSetStrategy>().Use<SiteMapBuilderSetStrategy>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,24 @@ protected override void Initialize()
// Configure the visitors
this.Container.RegisterType<ISiteMapNodeVisitor, UrlResolvingSiteMapNodeVisitor>();

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

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.
this.Container.RegisterType<ISiteMapBuilder, XmlSiteMapBuilder>("xmlSiteMapBuilder", new InjectionConstructor(new ResolvedParameter<IXmlSource>("file1XmlSource"), new ResolvedParameter<ISiteMapXmlReservedAttributeNameProvider>("nameProvider"), typeof(INodeKeyGenerator), typeof(IDynamicNodeBuilder), typeof(ISiteMapNodeFactory), typeof(ISiteMapXmlNameProvider)));
this.Container.RegisterType<ISiteMapBuilder, ReflectionSiteMapBuilder>("reflectionSiteMapBuilder", new InjectionConstructor(includeAssembliesForScan, new List<string>(), new ResolvedParameter<ISiteMapXmlReservedAttributeNameProvider>("nameProvider"), typeof(INodeKeyGenerator), typeof(IDynamicNodeBuilder), typeof(ISiteMapNodeFactory), typeof(ISiteMapCacheKeyGenerator)));
this.Container.RegisterType<ISiteMapBuilder, VisitingSiteMapBuilder>("visitingSiteMapBuilder");
this.Container.RegisterType<ISiteMapBuilder, CompositeSiteMapBuilder>(new InjectionConstructor(new ResolvedArrayParameter<ISiteMapBuilder>(
new ResolvedParameter<ISiteMapBuilder>("xmlSiteMapBuilder"),
new ResolvedParameter<ISiteMapBuilder>("reflectionSiteMapBuilder"),
new ResolvedParameter<ISiteMapBuilder>("visitingSiteMapBuilder"))));
// 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",
Expand Down
Loading

0 comments on commit 425c15c

Please sign in to comment.