Skip to content

Commit

Permalink
Fixes #131, problems interoperating with ELMAH. Added configuration s…
Browse files Browse the repository at this point in the history
…etting to exclude namespaces from controller type resolution.
  • Loading branch information
NightOwl888 committed Apr 6, 2013
1 parent ef5a4fd commit fe40bbf
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/MvcSiteMapProvider/MvcMusicStore/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ protected void Application_Start()
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

// MvcSiteMapProvider Configuration
#if NET35
//#if NET35
MvcSiteMapProvider.DI.Composer.Compose();
#endif
//#endif
XmlSiteMapController.RegisterRoutes(RouteTable.Routes);

var container = DIConfig.Register();
MvcSiteMapProviderConfig.Register(container);
// NOTE: This check wouldn't have to be made in a real-world application - we do it
// in the demo because we want to support both the internal and external DI containers.
if (new MvcSiteMapProvider.DI.ConfigurationSettings().UseExternalDIContainer == true)
{
var container = DIConfig.Register();
MvcSiteMapProviderConfig.Register(container);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public ConfigurationSettings()
this.AttributesToIgnore = GetConfigurationValueOrFallback("MvcSiteMapProvider_AttributesToIgnore", "")
.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
this.CacheDuration = int.Parse(GetConfigurationValueOrFallback("MvcSiteMapProvider_CacheDuration", "5"));
this.ExcludeNamespacesForResolver = GetConfigurationValueOrFallback("MvcSiteMapProvider_ExcludeNamespacesForResolver", "")
.Split(new char[] { '|', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
}

public bool UseExternalDIContainer { get; private set; }
Expand All @@ -31,6 +33,7 @@ public ConfigurationSettings()
public IEnumerable<string> IncludeAssembliesForScan { get; private set; }
public IEnumerable<string> AttributesToIgnore { get; private set; }
public int CacheDuration { get; private set; }
public IEnumerable<string> ExcludeNamespacesForResolver { get; private set; }


private string GetConfigurationValueOrFallback(string name, string defaultValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ namespace MvcSiteMapProvider.DI
public class SiteMapFactoryContainer
{
public SiteMapFactoryContainer(
ConfigurationSettings settings,
IMvcContextFactory mvcContextFactory,
IUrlPath urlPath)
{
this.settings = settings;
this.mvcContextFactory = mvcContextFactory;
this.requestCache = this.mvcContextFactory.GetRequestCache();
this.urlPath = urlPath;
}

private readonly ConfigurationSettings settings;
private readonly IMvcContextFactory mvcContextFactory;
private readonly IRequestCache requestCache;
private readonly IUrlPath urlPath;
Expand Down Expand Up @@ -82,6 +85,7 @@ private ISiteMapChildStateFactory ResolveSiteMapChildStateFactory()
private IControllerTypeResolverFactory ResolveControllerTypeResolverFactory()
{
return new ControllerTypeResolverFactory(
settings.ExcludeNamespacesForResolver,
new ControllerBuilderAdaptor(ControllerBuilder.Current),
new BuildManagerAdaptor()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public SiteMapLoaderContainer(ConfigurationSettings settings)
this.siteMapXmlNameProvider = new SiteMapXmlNameProvider();
this.dynamicNodeBuilder = new DynamicNodeBuilder(this.nodeKeyGenerator, this.siteMapNodeFactory);
this.siteMapBuiderSetStrategy = this.ResolveSiteMapBuilderSetStrategy(settings);
var siteMapFactoryContainer = new SiteMapFactoryContainer(this.mvcContextFactory, this.urlPath);
var siteMapFactoryContainer = new SiteMapFactoryContainer(settings, this.mvcContextFactory, this.urlPath);
this.siteMapFactory = siteMapFactoryContainer.ResolveSiteMapFactory();
this.siteMapCreator = new SiteMapCreator(this.siteMapCacheKeyToBuilderSetMapper, this.siteMapBuiderSetStrategy, this.siteMapFactory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,30 @@ public class ControllerTypeResolver
: IControllerTypeResolver
{
public ControllerTypeResolver(
IEnumerable<string> areaNamespacesToIgnore,
RouteCollection routes,
IControllerBuilder controllerBuilder,
IBuildManager buildManager
)
{
if (areaNamespacesToIgnore == null)
throw new ArgumentNullException("areaNamespacesToIgnore");
if (routes == null)
throw new ArgumentNullException("routes");
if (controllerBuilder == null)
throw new ArgumentNullException("controllerBuilder");
if (buildManager == null)
throw new ArgumentNullException("buildManager");

this.areaNamespacesToIgnore = areaNamespacesToIgnore;
this.routes = routes;
this.controllerBuilder = controllerBuilder;
this.buildManager = buildManager;

Cache = new Dictionary<string, Type>();
}

protected readonly IEnumerable<string> areaNamespacesToIgnore;
protected readonly RouteCollection routes;
protected readonly IControllerBuilder controllerBuilder;
protected readonly IBuildManager buildManager;
Expand Down Expand Up @@ -73,7 +78,11 @@ public Type ResolveControllerType(string areaName, string controllerName)
}

// Find controller details
IEnumerable<string> areaNamespaces = FindNamespacesForArea(areaName, this.routes);
IEnumerable<string> areaNamespaces = (from ns in FindNamespacesForArea(areaName, this.routes)
where ns != "Elmah.Mvc"
where !this.areaNamespacesToIgnore.Contains(ns)
select ns).ToList();

string area = areaName;
string controller = controllerName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Web.Mvc;
using System;
using System.Collections.Generic;
using System.Web.Routing;
using MvcSiteMapProvider.Web.Compilation;

Expand All @@ -13,27 +15,32 @@ public class ControllerTypeResolverFactory
: IControllerTypeResolverFactory
{
public ControllerTypeResolverFactory(
IEnumerable<string> areaNamespacesToIgnore,
IControllerBuilder controllerBuilder,
IBuildManager buildManager
)
{
if (areaNamespacesToIgnore == null)
throw new ArgumentNullException("areaNamespacesToIgnore");
if (controllerBuilder == null)
throw new ArgumentNullException("controllerBuilder");
if (buildManager == null)
throw new ArgumentNullException("buildManager");

this.areaNamespacesToIgnore = areaNamespacesToIgnore;
this.controllerBuilder = controllerBuilder;
this.buildManager = buildManager;
}

protected readonly IEnumerable<string> areaNamespacesToIgnore;
protected readonly IControllerBuilder controllerBuilder;
protected readonly IBuildManager buildManager;

#region IControllerTypeResolverFactory Members

public IControllerTypeResolver Create(RouteCollection routes)
{
return new ControllerTypeResolver(routes, controllerBuilder, buildManager);
return new ControllerTypeResolver(areaNamespacesToIgnore, routes, controllerBuilder, buildManager);
}

#endregion
Expand Down

0 comments on commit fe40bbf

Please sign in to comment.