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

Commit

Permalink
Initial refactoring around registrations
Browse files Browse the repository at this point in the history
  • Loading branch information
grumpydev committed Apr 4, 2014
1 parent e5be6e3 commit 21c2f00
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 98 deletions.
6 changes: 3 additions & 3 deletions src/Nancy.Hosting.Aspnet/DefaultNancyAspNetBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ protected override IEnumerable<IApplicationStartup> GetApplicationStartupTasks()
/// <summary>
/// Gets all registered application registration tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
protected override IEnumerable<IApplicationRegistrations> GetApplicationRegistrationTasks()
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IRegistrations"/> instances.</returns>
protected override IEnumerable<IRegistrations> GetApplicationRegistrationTasks()
{
return this.ApplicationContainer.ResolveAll<IApplicationRegistrations>(false);
return this.ApplicationContainer.ResolveAll<IRegistrations>(false);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Nancy.Testing/ConfigurableBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ protected override IEnumerable<IApplicationStartup> GetApplicationStartupTasks()
/// <summary>
/// Gets all registered application registration tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
protected override IEnumerable<IApplicationRegistrations> GetApplicationRegistrationTasks()
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IRegistrations"/> instances.</returns>
protected override IEnumerable<IRegistrations> GetApplicationRegistrationTasks()
{
return this.ApplicationContainer.ResolveAll<IApplicationRegistrations>(false);
return this.ApplicationContainer.ResolveAll<IRegistrations>(false);
}

/// <summary>
Expand Down
30 changes: 15 additions & 15 deletions src/Nancy.Tests/Unit/Bootstrapper/NancyBootstrapperBaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public void Should_invoke_startup_tasks_after_registration_tasks()
var startup = A.Fake<IApplicationStartup>();
this.bootstrapper.OverriddenApplicationStartupTasks = new[] { startup };

var registrations = A.Fake<IApplicationRegistrations>();
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { registrations };
var registrations = A.Fake<IRegistrations>();
this.bootstrapper.OverriddenRegistrationTasks = new[] { registrations };

// When
using(var scope = Fake.CreateScope())
Expand All @@ -148,9 +148,9 @@ public void Should_register_application_registration_type_registrations_into_con
{
// Given
var typeRegistrations = new TypeRegistration[] { };
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.TypeRegistrations).Returns(typeRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand All @@ -164,9 +164,9 @@ public void Should_register_application_registration_task_collection_registratio
{
// Given
var collectionTypeRegistrations = new CollectionTypeRegistration[] { };
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.CollectionTypeRegistrations).Returns(collectionTypeRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand All @@ -180,9 +180,9 @@ public void Should_register_application_registration_instance_registrations_into
{
// Given
var instanceRegistrations = new InstanceRegistration[] { };
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.InstanceRegistrations).Returns(instanceRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand Down Expand Up @@ -255,7 +255,7 @@ internal class FakeBootstrapperBaseImplementation : NancyBootstrapperBase<FakeCo
public IEnumerable<InstanceRegistration> InstanceRegistrations { get; set; }
public List<ModuleRegistration> PassedModules { get; set; }
public IApplicationStartup[] OverriddenApplicationStartupTasks { get; set; }
public IApplicationRegistrations[] OverriddenApplicationRegistrationTasks { get; set; }
public IRegistrations[] OverriddenRegistrationTasks { get; set; }
public bool ShouldThrowWhenGettingEngine { get; set; }

public FakeBootstrapperBaseImplementation()
Expand Down Expand Up @@ -295,10 +295,10 @@ protected override IEnumerable<IApplicationStartup> GetApplicationStartupTasks()
/// <summary>
/// Gets all registered application registration tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
protected override IEnumerable<IApplicationRegistrations> GetApplicationRegistrationTasks()
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IRegistrations"/> instances.</returns>
protected override IEnumerable<IRegistrations> GetApplicationRegistrationTasks()
{
return this.OverriddenApplicationRegistrationTasks ?? new IApplicationRegistrations[] { };
return this.OverriddenRegistrationTasks ?? new IRegistrations[] { };
}

/// <summary>
Expand Down Expand Up @@ -428,10 +428,10 @@ protected override IEnumerable<IApplicationStartup> GetApplicationStartupTasks()
/// <summary>
/// Gets all registered application registration tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
protected override IEnumerable<IApplicationRegistrations> GetApplicationRegistrationTasks()
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IRegistrations"/> instances.</returns>
protected override IEnumerable<IRegistrations> GetApplicationRegistrationTasks()
{
return new IApplicationRegistrations[] { };
return new IRegistrations[] { };
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public void Should_not_register_request_lifetime_types_into_application_containe
new TypeRegistration(typeof(FakeBootstrapperBaseImplementation), typeof(FakeBootstrapperBaseImplementation), Lifetime.Transient),
new TypeRegistration(typeof(string), typeof(string), Lifetime.PerRequest),
};
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.TypeRegistrations).Returns(typeRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand All @@ -53,9 +53,9 @@ public void Should_register_request_lifetime_types_into_request_container_as_sin
new TypeRegistration(typeof(FakeBootstrapperBaseImplementation), typeof(FakeBootstrapperBaseImplementation), Lifetime.Transient),
new TypeRegistration(typeof(string), typeof(string), Lifetime.PerRequest),
};
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.TypeRegistrations).Returns(typeRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand All @@ -74,9 +74,9 @@ public void Should_not_register_request_lifetime_collectiontypes_into_applicatio
new CollectionTypeRegistration(typeof(FakeBootstrapperBaseImplementation), new[] { typeof(FakeBootstrapperBaseImplementation) }, Lifetime.Transient),
new CollectionTypeRegistration(typeof(string), new[] { typeof(string) }, Lifetime.PerRequest),
};
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.CollectionTypeRegistrations).Returns(collectionRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand All @@ -97,9 +97,9 @@ public void Should_register_request_lifetime_collectiontypes_into_request_contai
new CollectionTypeRegistration(typeof(FakeBootstrapperBaseImplementation), new[] { typeof(FakeBootstrapperBaseImplementation) }, Lifetime.Transient),
new CollectionTypeRegistration(typeof(string), new[] { typeof(string) }, Lifetime.PerRequest),
};
var startupStub = A.Fake<IApplicationRegistrations>();
var startupStub = A.Fake<IRegistrations>();
A.CallTo(() => startupStub.CollectionTypeRegistrations).Returns(collectionRegistrations);
this.bootstrapper.OverriddenApplicationRegistrationTasks = new[] { startupStub };
this.bootstrapper.OverriddenRegistrationTasks = new[] { startupStub };

// When
this.bootstrapper.Initialise();
Expand Down Expand Up @@ -131,7 +131,7 @@ internal class FakeBootstrapper : NancyBootstrapperWithRequestContainerBase<Fake

public IApplicationStartup[] OverriddenApplicationStartupTasks { get; set; }

public IApplicationRegistrations[] OverriddenApplicationRegistrationTasks { get; set; }
public IRegistrations[] OverriddenRegistrationTasks { get; set; }

public bool ShouldThrowWhenGettingEngine { get; set; }

Expand Down Expand Up @@ -172,10 +172,10 @@ protected override IEnumerable<IApplicationStartup> GetApplicationStartupTasks()
/// <summary>
/// Gets all registered application registration tasks
/// </summary>
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IApplicationRegistrations"/> instances.</returns>
protected override IEnumerable<IApplicationRegistrations> GetApplicationRegistrationTasks()
/// <returns>An <see cref="IEnumerable{T}"/> instance containing <see cref="IRegistrations"/> instances.</returns>
protected override IEnumerable<IRegistrations> GetApplicationRegistrationTasks()
{
return this.OverriddenApplicationRegistrationTasks ?? new IApplicationRegistrations[] { };
return this.OverriddenRegistrationTasks ?? new IRegistrations[] { };
}

protected override void ConfigureApplicationContainer(FakeContainer existingContainer)
Expand Down
2 changes: 1 addition & 1 deletion src/Nancy.Validation.DataAnnotations/Registrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Nancy.Validation.DataAnnotations
/// <summary>
/// Application registrations for Data Annotations validation types.
/// </summary>
public class Registrations : ApplicationRegistrations
public class Registrations : Bootstrapper.Registrations
{
/// <summary>
/// Creates a new instance of the <see cref="Registrations"/> class, that performs
Expand Down
2 changes: 1 addition & 1 deletion src/Nancy.Validation.FluentValidation/Registrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Nancy.Validation.FluentValidation
/// <summary>
/// Application registrations for Fluent Validation types.
/// </summary>
public class Registrations : ApplicationRegistrations
public class Registrations : Bootstrapper.Registrations
{
/// <summary>
/// Creates a new instance of the <see cref="Registrations"/> class, that performs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
///
/// This can be overridden in a bootstrapper.
/// </summary>
public class DotLiquidApplicationRegistrations : ApplicationRegistrations
public class DotLiquidRegistrations : Registrations
{
/// <summary>
/// Register the <c>RubyNamingConvention</c> as the default.
/// </summary>
public DotLiquidApplicationRegistrations()
public DotLiquidRegistrations()
{
this.RegisterWithDefault<INamingConvention>(typeof(RubyNamingConvention));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<Link>Properties\SharedAssemblyInfo.cs</Link>
</Compile>
<Compile Include="DefaultFileSystemFactory.cs" />
<Compile Include="DotLiquidApplicationRegistrations.cs" />
<Compile Include="DotLiquidRegistrations.cs" />
<Compile Include="DotLiquidViewEngine.cs" />
<Compile Include="DynamicDrop.cs" />
<Compile Include="IFileSystemFactory.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Nancy.ViewEngines.Razor
/// <summary>
/// Default dependency registrations for the <see cref="RazorViewEngine"/> class.
/// </summary>
public class RazorViewEngineApplicationRegistrations : ApplicationRegistrations
public class RazorViewEngineRegistrations : Registrations
{
public RazorViewEngineApplicationRegistrations()
public RazorViewEngineRegistrations()
{
this.RegisterWithDefault<IRazorConfiguration>(typeof(DefaultRazorConfiguration));
}
Expand Down
19 changes: 3 additions & 16 deletions src/Nancy/Bootstrapper/IApplicationRegistrations.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
namespace Nancy.Bootstrapper
{
using System.Collections.Generic;
using System;

/// <summary>
/// Provides a hook to perform registrations during application startup.
/// </summary>
public interface IApplicationRegistrations
[Obsolete("IApplicationRegistrations is now obsolete, please use IRegistrations instead.")]
public interface IApplicationRegistrations : IRegistrations
{
/// <summary>
/// Gets the type registrations to register for this startup task
/// </summary>
IEnumerable<TypeRegistration> TypeRegistrations { get; }

/// <summary>
/// Gets the collection registrations to register for this startup task
/// </summary>
IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations { get; }

/// <summary>
/// Gets the instance registrations to register for this startup task
/// </summary>
IEnumerable<InstanceRegistration> InstanceRegistrations { get; }
}
}
25 changes: 25 additions & 0 deletions src/Nancy/Bootstrapper/IRegistrations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace Nancy.Bootstrapper
{
using System.Collections.Generic;

/// <summary>
/// Provides a hook to perform registrations during application startup.
/// </summary>
public interface IRegistrations
{
/// <summary>
/// Gets the type registrations to register for this startup task
/// </summary>
IEnumerable<TypeRegistration> TypeRegistrations { get; }

/// <summary>
/// Gets the collection registrations to register for this startup task
/// </summary>
IEnumerable<CollectionTypeRegistration> CollectionTypeRegistrations { get; }

/// <summary>
/// Gets the instance registrations to register for this startup task
/// </summary>
IEnumerable<InstanceRegistration> InstanceRegistrations { get; }
}
}
Loading

5 comments on commit 21c2f00

@xt0rted
Copy link
Contributor

Choose a reason for hiding this comment

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

@grumpydev I just tried to update my lightlies since the Pre908 version of Nancy is no longer listed. The issue with that is not every package has been updated that this commit touched, such as Nancy.Validation.* and Nancy.Viewengines.*. Because of that the AppDomainAssemblyTypeScanner keeps crashing saying it can't find Nancy.Bootstrapper.ApplicationRegistrations. Any chance of forcing new builds to myget to fix this?

@xt0rted
Copy link
Contributor

Choose a reason for hiding this comment

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

@grumpydev After looking into this some more it turns out NuGet is just being a pain and saying Pre908 is newer than Pre1355. This is why the UI isn't showing the 1xxx builds. It's also why MyGet doesn't list them as the most current.

My other issue is that the Structuremap bootstrapper isn't being built against the refactored base class yet.

For now I'm reverting back to the older pre release builds. That is unless there's an example of how to bootstrap TinyIoC in my OWIN startup class 😄

@grumpydev
Copy link
Member Author

Choose a reason for hiding this comment

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

@xt0rted yeah, I manually delisted the older packages for some of the main ones but lost the will to live so didn't do them all :) I needed this PR pulled in before I could update the other bootstrappers, that's my job for this weekend.

Not sure what you mean with the tinyioc comment though.

@xt0rted
Copy link
Contributor

Choose a reason for hiding this comment

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

I've been using Structuremap with my other middleware and when I tried switching it out for TinyIoC everything that ran before Nancy worked ok, but once the bootstrapper ran it would crash with various missing dependency errors. Now that I cleaned up the mixed nightly versions I'll give it another try.

@grumpydev
Copy link
Member Author

Choose a reason for hiding this comment

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

@xt0rted : all the bootstrappers are now updated

Please sign in to comment.