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
Show file tree
Hide file tree
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
Expand Up @@ -7,7 +7,7 @@ namespace Nancy.Demo.Authentication.Forms.TestingDemo

public class TestBootstrapper : FormsAuthBootstrapper
{
protected override Type RootPathProvider
protected override IRootPathProvider RootPathProvider
{
get
{
Expand All @@ -25,7 +25,7 @@ protected override Type RootPathProvider

FakeRootPathProvider.RootPath = rootPath;

return typeof(FakeRootPathProvider);
return new FakeRootPathProvider();
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions src/Nancy.Testing/ConfigurableBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
28 changes: 24 additions & 4 deletions src/Nancy/Bootstrapper/NancyBootstrapperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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),
};
}

Expand Down Expand Up @@ -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;
}
}
}