Skip to content
Browse files

Merge pull request #963 from thecodejunkie/rootpathproviderchange

Changed RootPathProvider to return an instance
  • Loading branch information...
2 parents 5d7d005 + 1d567cf commit 3be777396775cac8afd0c59b8e2a984c9ca7c3d2 @grumpydev grumpydev committed Feb 8, 2013
View
4 src/Nancy.Demo.Authentication.Forms.TestingDemo/TestBootstrapper.cs
@@ -7,7 +7,7 @@ namespace Nancy.Demo.Authentication.Forms.TestingDemo
public class TestBootstrapper : FormsAuthBootstrapper
{
- protected override Type RootPathProvider
+ protected override IRootPathProvider RootPathProvider
{
get
{
@@ -25,7 +25,7 @@ protected override Type RootPathProvider
FakeRootPathProvider.RootPath = rootPath;
- return typeof(FakeRootPathProvider);
+ return new FakeRootPathProvider();
}
}
}
View
10 src/Nancy.Testing/ConfigurableBootstrapper.cs
@@ -277,15 +277,9 @@ protected override DiagnosticsConfiguration DiagnosticsConfiguration
/// <summary>
/// Gets the root path provider
/// </summary>
- protected override Type RootPathProvider
+ protected override IRootPathProvider RootPathProvider
{
- get
- {
- var rootPathProvider =
- this.Resolve<IRootPathProvider>();
-
- return (rootPathProvider != null) ? rootPathProvider.First() : base.RootPathProvider;
- }
+ get { return new DefaultRootPathProvider(); }
}
/// <summary>
View
28 src/Nancy/Bootstrapper/NancyBootstrapperBase.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
- using System.Reflection;
using Diagnostics;
using Nancy.Cryptography;
using Nancy.ModelBinding;
@@ -27,6 +26,11 @@ public abstract class NancyBootstrapperBase<TContainer> : INancyBootstrapper, IN
private bool initialised;
/// <summary>
+ /// Stores the <see cref="IRootPathProvider"/> used by Nancy
+ /// </summary>
+ private IRootPathProvider rootPathProvider;
+
+ /// <summary>
/// Default Nancy conventions
/// </summary>
private readonly NancyConventions conventions;
@@ -163,9 +167,9 @@ protected virtual IEnumerable<Type> ApplicationRegistrationTasks
/// <summary>
/// Gets the root path provider
/// </summary>
- protected virtual Type RootPathProvider
+ protected virtual IRootPathProvider RootPathProvider
{
- get { return AppDomainAssemblyTypeScanner.TypesOf<IRootPathProvider>(true).FirstOrDefault() ?? typeof(DefaultRootPathProvider); }
+ get { return this.rootPathProvider ?? (this.rootPathProvider = GetRootPathProvider()); }
}
/// <summary>
@@ -506,7 +510,7 @@ protected virtual void ConfigureConventions(NancyConventions nancyConventions)
/// <returns>Collection of TypeRegistration types</returns>
private IEnumerable<TypeRegistration> GetAdditionalTypes()
{
- return new[] { new TypeRegistration(typeof(IRootPathProvider), this.RootPathProvider) };
+ return Enumerable.Empty<TypeRegistration>();
}
/// <summary>
@@ -520,6 +524,7 @@ private IEnumerable<InstanceRegistration> GetAdditionalInstances()
new InstanceRegistration(typeof(CryptographyConfiguration), this.CryptographyConfiguration),
new InstanceRegistration(typeof(NancyInternalConfiguration), this.InternalConfiguration),
new InstanceRegistration(typeof(DiagnosticsConfiguration), this.DiagnosticsConfiguration),
+ new InstanceRegistration(typeof(IRootPathProvider), this.RootPathProvider),
};
}
@@ -555,5 +560,20 @@ private INancyEngine SafeGetNancyEngineInstance()
ex);
}
}
+
+
+ private static IRootPathProvider GetRootPathProvider()
+ {
+ var providerType = AppDomainAssemblyTypeScanner
+ .TypesOf<IRootPathProvider>(ScanMode.ExcludeNancy)
+ .SingleOrDefault();
+
+ if (providerType == null)
+ {
+ providerType = typeof(DefaultRootPathProvider);
+ }
+
+ return Activator.CreateInstance(providerType) as IRootPathProvider;
+ }
}
}

0 comments on commit 3be7773

Please sign in to comment.
Something went wrong with that request. Please try again.