Permalink
Browse files

Renamed IResourceAssemblyProvider

It's now called IAssemblyProvider and was moved to the Nancy
namespace.
  • Loading branch information...
1 parent d46b4d7 commit 9e8235667b41f4eac90ddd6b25dad6479960f25c @thecodejunkie thecodejunkie committed Dec 29, 2012
@@ -1137,24 +1137,24 @@ public ConfigurableBoostrapperConfigurator RequestDispatcher(IRequestDispatcher
}
/// <summary>
- /// Configures the bootstrapper to use the provided instance of <see cref="IResourceAssemblyProvider"/>.
+ /// Configures the bootstrapper to use the provided instance of <see cref="IAssemblyProvider"/>.
/// </summary>
- /// <param name="resourceAssemblyProvider">The <see cref="IResourceAssemblyProvider"/> instance that should be used by the bootstrapper.</param>
+ /// <param name="assemblyProvider">The <see cref="IAssemblyProvider"/> instance that should be used by the bootstrapper.</param>
/// <returns>A reference to the current <see cref="ConfigurableBoostrapperConfigurator"/>.</returns>
- public ConfigurableBoostrapperConfigurator ResourceAssemblyProvider(IResourceAssemblyProvider resourceAssemblyProvider)
+ public ConfigurableBoostrapperConfigurator ResourceAssemblyProvider(IAssemblyProvider assemblyProvider)
{
this.bootstrapper.registeredInstances.Add(
- new InstanceRegistration(typeof(IResourceAssemblyProvider), resourceAssemblyProvider));
+ new InstanceRegistration(typeof(IAssemblyProvider), assemblyProvider));
return this;
}
/// <summary>
- /// Configures the bootstrapper to create an <see cref="IResourceAssemblyProvider"/> instance of the specified type.
+ /// Configures the bootstrapper to create an <see cref="IAssemblyProvider"/> instance of the specified type.
/// </summary>
- /// <typeparam name="T">The type of the <see cref="IResourceAssemblyProvider"/> that the bootstrapper should use.</typeparam>
+ /// <typeparam name="T">The type of the <see cref="IAssemblyProvider"/> that the bootstrapper should use.</typeparam>
/// <returns>A reference to the current <see cref="ConfigurableBoostrapperConfigurator"/>.</returns>
- public ConfigurableBoostrapperConfigurator ResourceAssemblyProvider<T>() where T : IResourceAssemblyProvider
+ public ConfigurableBoostrapperConfigurator ResourceAssemblyProvider<T>() where T : IAssemblyProvider
{
this.bootstrapper.configuration.ResourceAssemblyProvider = typeof(T);
return this;
@@ -11,7 +11,7 @@ public class ResourceBasedTextResourceFixture
public void Should_Return_Null_If_No_Assembly_Found()
{
//Given
- var resourceAssemblyProvider = A.Fake<IResourceAssemblyProvider>();
+ var resourceAssemblyProvider = A.Fake<IAssemblyProvider>();
A.CallTo(() => resourceAssemblyProvider.GetAssembliesToScan()).Returns(new[] { typeof(NancyEngine).Assembly });
var defaultTextResource = new ResourceBasedTextResource(resourceAssemblyProvider);
@@ -12,14 +12,14 @@ namespace Nancy.Tests.Unit.ViewEngines
public class ResourceViewLocationProviderFixture
{
private readonly IResourceReader reader;
- private readonly IResourceAssemblyProvider assemblyProvider;
+ private readonly IAssemblyProvider assemblyProvider;
private readonly ResourceViewLocationProvider viewProvider;
public ResourceViewLocationProviderFixture()
{
ResourceViewLocationProvider.Ignore.Clear();
this.reader = A.Fake<IResourceReader>();
- this.assemblyProvider = A.Fake<IResourceAssemblyProvider>();
+ this.assemblyProvider = A.Fake<IAssemblyProvider>();
this.viewProvider = new ResourceViewLocationProvider(this.reader, this.assemblyProvider);
if (!ResourceViewLocationProvider.RootNamespaces.ContainsKey(this.GetType().Assembly))
@@ -92,7 +92,7 @@ public static NancyInternalConfiguration Default
RouteDescriptionProvider = typeof(DefaultRouteDescriptionProvider),
CultureService = typeof(DefaultCultureService),
TextResource = typeof(ResourceBasedTextResource),
- ResourceAssemblyProvider = typeof(DefaultResourceAssemblyProvider),
+ ResourceAssemblyProvider = typeof(DefaultAssemblyProvider),
};
}
}
@@ -264,7 +264,7 @@ public IEnumerable<TypeRegistration> GetTypeRegistations()
new TypeRegistration(typeof(IRouteDescriptionProvider), this.RouteDescriptionProvider),
new TypeRegistration(typeof(ICultureService), this.CultureService),
new TypeRegistration(typeof(ITextResource), this.TextResource),
- new TypeRegistration(typeof(IResourceAssemblyProvider), this.ResourceAssemblyProvider),
+ new TypeRegistration(typeof(IAssemblyProvider), this.ResourceAssemblyProvider),
};
}
@@ -0,0 +1,49 @@
+namespace Nancy
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Reflection;
+ using Nancy.Bootstrapper;
+
+ /// <summary>
+ /// Default set of assemblies that should be scanned for views embedded as resources.
+ /// </summary>
+ public class DefaultAssemblyProvider : IAssemblyProvider
+ {
+ private IEnumerable<Assembly> filteredAssemblies;
+
+ private readonly List<Func<Assembly, bool>> excludedAssemblies = new List<Func<Assembly, bool>>()
+ {
+ asm => asm.FullName.StartsWith("Microsoft.", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("System.", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("System,", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("CR_ExtUnitTest", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("mscorlib,", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("CR_VSTest", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("DevExpress.CodeRush", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("IronPython", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("IronRuby", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("xunit", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("Nancy.Testing", StringComparison.InvariantCulture),
+ asm => asm.FullName.StartsWith("MonoDevelop.NUnit", StringComparison.InvariantCulture),
+ };
+
+ /// <summary>
+ /// Gets a list of assemblies that should be scanned for views.
+ /// </summary>
+ /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Assembly"/> instances.</returns>
+ public IEnumerable<Assembly> GetAssembliesToScan()
+ {
+ return (this.filteredAssemblies ?? (this.filteredAssemblies = GetFilteredAssemblies()));
+ }
+
+ private IEnumerable<Assembly> GetFilteredAssemblies()
+ {
+ return AppDomainAssemblyTypeScanner
+ .Assemblies
+ .Where(x => !x.IsDynamic)
+ .Where(x => !this.excludedAssemblies.Any(asm => asm.Invoke(x)));
+ }
+ }
+}
@@ -1,42 +0,0 @@
-namespace Nancy
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
- using Nancy.Bootstrapper;
-
- /// <summary>
- /// Default set of assemblies that should be scanned for views embedded as resources.
- /// </summary>
- public class DefaultResourceAssemblyProvider : IResourceAssemblyProvider
- {
- /// <summary>
- /// Gets a list of assemblies that should be scanned for views.
- /// </summary>
- /// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Assembly"/> instances.</returns>
- public IEnumerable<Assembly> GetAssembliesToScan()
- {
- var excludedAssemblies = new List<Func<Assembly, bool>>()
- {
- asm => asm.FullName.StartsWith("Microsoft.", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("System.", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("System,", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("CR_ExtUnitTest", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("mscorlib,", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("CR_VSTest", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("DevExpress.CodeRush", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("IronPython", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("IronRuby", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("xunit", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("Nancy.Testing", StringComparison.InvariantCulture),
- asm => asm.FullName.StartsWith("MonoDevelop.NUnit", StringComparison.InvariantCulture),
- };
-
- return AppDomainAssemblyTypeScanner
- .Assemblies
- .Where(x => !x.IsDynamic)
- .Where(x => !excludedAssemblies.Any(asm => asm.Invoke(x)));
- }
- }
-}
@@ -4,12 +4,12 @@
using System.Reflection;
/// <summary>
- /// Defines the functionality for retrieving which assemblies that should have their resources scanned for views.
+ /// Defines the functionality for retrieving which assemblies that should be used by Nancy.
/// </summary>
- public interface IResourceAssemblyProvider
+ public interface IAssemblyProvider
{
/// <summary>
- /// Gets a list of assemblies that should be scanned for views embedded as resources.
+ /// Gets a list of assemblies that should be scanned.
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="Assembly"/> instances.</returns>
IEnumerable<Assembly> GetAssembliesToScan();
@@ -11,19 +11,19 @@ namespace Nancy.Localization
/// </summary>
public class ResourceBasedTextResource : ITextResource
{
- private readonly IResourceAssemblyProvider resourceAssemblyProvider;
+ private readonly IAssemblyProvider assemblyProvider;
private readonly Assembly culturedAssembly;
private readonly ResourceManager resourceManager;
/// <summary>
/// Initializes a new instance of <see cref="ResourceBasedTextResource"/> to read strings from *.resx files
/// </summary>
/// <remarks>Looks for *.resx files in a Resources folder with files called Text.resx as default or Text.CultureName.resx eg/ Text.en-GB.resx</remarks>
- public ResourceBasedTextResource(IResourceAssemblyProvider resourceAssemblyProvider)
+ public ResourceBasedTextResource(IAssemblyProvider assemblyProvider)
{
- this.resourceAssemblyProvider = resourceAssemblyProvider;
+ this.assemblyProvider = assemblyProvider;
- this.culturedAssembly = this.resourceAssemblyProvider
+ this.culturedAssembly = this.assemblyProvider
.GetAssembliesToScan()
.FirstOrDefault(x => x.GetManifestResourceNames().Any(y => y.Contains(".Resources.Text")));
View
@@ -271,7 +271,7 @@
<Compile Include="ViewEngines\DefaultFileSystemReader.cs" />
<Compile Include="ViewEngines\DefaultRenderContext.cs" />
<Compile Include="ViewEngines\DefaultRenderContextFactory.cs" />
- <Compile Include="DefaultResourceAssemblyProvider.cs" />
+ <Compile Include="DefaultAssemblyProvider.cs" />
<Compile Include="ViewEngines\DefaultResourceReader.cs" />
<Compile Include="Localization\ResourceBasedTextResource.cs" />
<Compile Include="ViewEngines\DefaultViewCache.cs" />
@@ -374,7 +374,7 @@
<Compile Include="ViewEngines\IFileSystemReader.cs" />
<Compile Include="ViewEngines\IRenderContext.cs" />
<Compile Include="ViewEngines\IRenderContextFactory.cs" />
- <Compile Include="IResourceAssemblyProvider.cs" />
+ <Compile Include="IAssemblyProvider.cs" />
<Compile Include="ViewEngines\IResourceReader.cs" />
<Compile Include="Localization\ITextResource.cs" />
<Compile Include="ViewEngines\IViewCache.cs" />
@@ -12,7 +12,7 @@
public class ResourceViewLocationProvider : IViewLocationProvider
{
private readonly IResourceReader resourceReader;
- private readonly IResourceAssemblyProvider resourceAssemblyProvider;
+ private readonly IAssemblyProvider assemblyProvider;
/// <summary>
/// User-configured root namespaces for assemblies.
@@ -28,19 +28,19 @@ public class ResourceViewLocationProvider : IViewLocationProvider
/// Initializes a new instance of the <see cref="ResourceViewLocationProvider"/> class.
/// </summary>
public ResourceViewLocationProvider()
- : this(new DefaultResourceReader(), new DefaultResourceAssemblyProvider())
+ : this(new DefaultResourceReader(), new DefaultAssemblyProvider())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ResourceViewLocationProvider"/> class.
/// </summary>
/// <param name="resourceReader">An <see cref="IResourceReader"/> instance that should be used when extracting embedded views.</param>
- /// <param name="resourceAssemblyProvider">An <see cref="IResourceAssemblyProvider"/> instance that should be used to determine which assemblies to scan for embedded views.</param>
- public ResourceViewLocationProvider(IResourceReader resourceReader, IResourceAssemblyProvider resourceAssemblyProvider)
+ /// <param name="assemblyProvider">An <see cref="IAssemblyProvider"/> instance that should be used to determine which assemblies to scan for embedded views.</param>
+ public ResourceViewLocationProvider(IResourceReader resourceReader, IAssemblyProvider assemblyProvider)
{
this.resourceReader = resourceReader;
- this.resourceAssemblyProvider = resourceAssemblyProvider;
+ this.assemblyProvider = assemblyProvider;
}
/// <summary>
@@ -56,7 +56,7 @@ public IEnumerable<ViewLocationResult> GetLocatedViews(IEnumerable<string> suppo
return Enumerable.Empty<ViewLocationResult>();
}
- return this.resourceAssemblyProvider
+ return this.assemblyProvider
.GetAssembliesToScan()
.Where(x => !Ignore.Contains(x))
.SelectMany(x => GetViewLocations(x, supportedViewExtensions));

0 comments on commit 9e82356

Please sign in to comment.