Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix ignored assemblies. Loads them as late as possible. #638

Closed
wants to merge 6 commits into from

3 participants

Albert-Jan Nijburg Steven Robbins Andreas Håkansson
Albert-Jan Nijburg

Loads the assemblies and scans through them when it is asked for it the first time. Updates the ignored assemblies when they're changed.

Steven Robbins grumpydev closed this pull request from a commit
Steven Robbins grumpydev Updated assembly scanning logic
Moved loading of nancy assemblies to "Initialise" in the bootstrapper,
rather than in the ctor, and set the ignored assemblies on the
ADATS in the same place. Initialise is called before any container
resolution or anything else happens, so now the ignore assemblies should
be set before anything needs the scanner.

Also move the logic to only include assemblies that reference nancy assemblies
from the resource based text resource to the resource assembly provider
so all resource based providers can use the same filtered list.

Fixes #504
Closes #638
Fixes #418
2ecc7f7
Steven Robbins grumpydev closed this in 2ecc7f7
Albert-Jan Nijburg

@grumpydev isn't the adats used to scan for the bootstrapper? Shouldn't it ignore the ignored assemblies when doing that?

Steven Robbins
Owner

It is, but the ignored assemblies are set in the bootstrapper, and it's only done once on app startup, so I'm not too concerned about that.. as far as I know we've never had an issue where the bootstrapper locator crashed.

Albert-Jan Nijburg

There has been see issue #629

Steven Robbins
Owner

That says there's issues with the scanner, but not that the bootstrapper locator crashes.. I've seen scanner issues before, but never had them in the locator.

Steven Robbins
Owner

Just added a nancy app to an existing mvc site (as mentioned in #629) and it works fine.

Albert-Jan Nijburg

Allright but the adats does not ignore the ignored assemblies when looking for a bootstrapper.

Steven Robbins
Owner

I didn't say it did, I said I didn't think that was a problem :-)

I'm actually thinking I might set a default in the static ctor of ADATS that ignores any assembly that doesn't have a nancy reference.. that should speed up the initial scan for the bootstrapper somewhat, and fix your concerns about it blowing up?

Albert-Jan Nijburg

That would be a smart fix indeed! :) I didn't really have that many concerns about it, but the remaining concerns would definatelly be fixed :P. I didn't know you could see which references an assembly has.

Andreas Håkansson
Steven Robbins
Owner

See #916

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
25 src/Nancy.Tests/Unit/Bootstrapper/NancyInternalConfigurationFixture.cs
View
@@ -68,6 +68,31 @@ public void Should_not_be_valid_if_any_types_null()
}
[Fact]
+ public void Should_set_ignored_assemblies_on_appdomainassemblytypescanner_when_creating_default_config()
+ {
+ //Given
+ AppDomainAssemblyTypeScanner.IgnoredAssemblies = null;
+
+ //When
+ var config = NancyInternalConfiguration.Default;
+
+ //Then
+ AppDomainAssemblyTypeScanner.Types.Where(t => config.IgnoredAssemblies.Any(f => f(t.Assembly))).Count().
+ ShouldEqual(0);
+ }
+
+ [Fact]
+ public void Should_update_ignored_assemblies_on_appdomianassemblystypescanner_when_adding_one_to_the_config()
+ {
+ //Given & When
+ var config = NancyInternalConfiguration.Default.WithIgnoredAssembly(f => f.FullName.StartsWith("Machine."));
+
+ //Then
+ AppDomainAssemblyTypeScanner.Types.Where (t => config.IgnoredAssemblies.Any (f => f (t.Assembly))).Count ().
+ ShouldEqual (0);
+ }
+
+ [Fact]
public void Should_allow_additional_ignored_assemblies()
{
Func<Assembly, bool> predicate = asm => asm.FullName.StartsWith("moo");
3  src/Nancy.Tests/Unit/Conventions/DefaultStaticContentsConventionsFixture.cs
View
@@ -2,7 +2,7 @@
{
using System;
using System.Collections.Generic;
- using System.IO;
+ using Nancy.Bootstrapper;
using Nancy.Conventions;
using Xunit;
@@ -13,6 +13,7 @@ public class DefaultStaticContentsConventionsFixture
public DefaultStaticContentsConventionsFixture()
{
+ AppDomainAssemblyTypeScanner.LoadNancyAssemblies();
this.conventions = new NancyConventions();
this.staticContentsConventions = new DefaultStaticContentsConventions();
}
2  src/Nancy.Tests/Unit/Conventions/DefaultViewLocationConventionsFixture.cs
View
@@ -2,6 +2,7 @@ namespace Nancy.Tests.Unit.Conventions
{
using System;
using System.Collections.Generic;
+ using Nancy.Bootstrapper;
using Nancy.Conventions;
using Nancy.ViewEngines;
using Xunit;
@@ -13,6 +14,7 @@ public class DefaultViewLocationConventionsFixture
public DefaultViewLocationConventionsFixture()
{
+ AppDomainAssemblyTypeScanner.LoadNancyAssemblies ();
this.conventions = new NancyConventions();
this.viewLocationConventions = new DefaultViewLocationConventions();
}
16 src/Nancy/Bootstrapper/AppDomainAssemblyTypeScanner.cs
View
@@ -13,11 +13,6 @@ namespace Nancy.Bootstrapper
/// </summary>
public static class AppDomainAssemblyTypeScanner
{
- static AppDomainAssemblyTypeScanner()
- {
- LoadNancyAssemblies();
- }
-
/// <summary>
/// Nancy core assembly
/// </summary>
@@ -66,6 +61,10 @@ public static IEnumerable<Type> Types
{
get
{
+ if (!nancyAssembliesLoaded)
+ {
+ LoadNancyAssemblies();
+ }
return types;
}
}
@@ -146,6 +145,13 @@ private static void UpdateAssemblies()
/// </summary>
public static void LoadNancyAssemblies()
{
+ //If the ignoredassemblies is null at this point get the default ignored assemblies from the internal config.
+ //These will get updates when the user adjusts them.
+ if (IgnoredAssemblies == null)
+ {
+ IgnoredAssemblies = NancyInternalConfiguration.DefaultIgnoredAssemblies;
+ }
+
if (nancyAssembliesLoaded)
{
return;
4 src/Nancy/Bootstrapper/NancyBootstrapperBase.cs
View
@@ -53,8 +53,6 @@ public abstract class NancyBootstrapperBase<TContainer> : INancyBootstrapper, IN
/// </summary>
protected NancyBootstrapperBase()
{
- AppDomainAssemblyTypeScanner.LoadNancyAssemblies();
-
this.ApplicationPipelines = new Pipelines();
this.conventions = new NancyConventions();
}
@@ -209,7 +207,7 @@ public void Initialise()
{
throw new InvalidOperationException("Configuration is invalid");
}
-
+
this.ApplicationContainer = this.GetApplicationContainer();
this.RegisterBootstrapperTypes(this.ApplicationContainer);
3  src/Nancy/Bootstrapper/NancyInternalConfiguration.cs
View
@@ -51,6 +51,7 @@ public static NancyInternalConfiguration Default
{
get
{
+ UpdateIgnoredAssemblies(DefaultIgnoredAssemblies);
return new NancyInternalConfiguration
{
RouteResolver = typeof(DefaultRouteResolver),
@@ -251,6 +252,8 @@ public IEnumerable<CollectionTypeRegistration> GetCollectionTypeRegistrations()
public NancyInternalConfiguration WithIgnoredAssembly(Func<Assembly, bool> ignorePredicate)
{
this.ignoredAssemblies.Add(ignorePredicate);
+
+ UpdateIgnoredAssemblies(IgnoredAssemblies);
return this;
}
Something went wrong with that request. Please try again.