Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.

Changed RootPathProvider to return an instance #963

Merged
merged 2 commits into from
Feb 8, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
10 changes: 2 additions & 8 deletions src/Nancy.Testing/ConfigurableBootstrapper.cs
Original file line number Diff line number Diff line change
@@ -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>
28 changes: 24 additions & 4 deletions src/Nancy/Bootstrapper/NancyBootstrapperBase.cs
Original file line number Diff line number Diff line change
@@ -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;
@@ -26,6 +25,11 @@ public abstract class NancyBootstrapperBase<TContainer> : INancyBootstrapper, IN
/// </summary>
private bool initialised;

/// <summary>
/// Stores the <see cref="IRootPathProvider"/> used by Nancy
/// </summary>
private IRootPathProvider rootPathProvider;

/// <summary>
/// Default Nancy conventions
/// </summary>
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this exclude nancy? going to be non-deterministic otherwise?

.TypesOf<IRootPathProvider>(ScanMode.ExcludeNancy)
.SingleOrDefault();

if (providerType == null)
{
providerType = typeof(DefaultRootPathProvider);
}

return Activator.CreateInstance(providerType) as IRootPathProvider;
}
}
}