Skip to content

Commit

Permalink
added the FubuRegistry.WithTypes() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Nov 17, 2011
1 parent d1fae65 commit a316e6a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/FubuMVC.Core/FubuRegistry.Expressions.cs
Expand Up @@ -269,8 +269,6 @@ public void IncludeDiagnostics(Action<IDiagnosticsConfigurationExpression> confi
});
}



/// <summary>
/// Gets the level of diagnostics specified for this <see cref="FubuRegistry"/>
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions src/FubuMVC.Core/FubuRegistry.cs
Expand Up @@ -136,10 +136,24 @@ public BehaviorGraph BuildGraph()
return BuildLightGraph();
}

private readonly IList<Action<TypePool>> _scanningOperations = new List<Action<TypePool>>();

/// <summary>
/// Access the TypePool with all the assemblies represented in the AppliesTo expressions
/// to make conventional registrations of any kind
/// </summary>
/// <param name="configuration"></param>
public void WithTypes(Action<TypePool> configuration)
{
_scanningOperations.Add(configuration);
}

public BehaviorGraph BuildLightGraph()
{
var graph = new BehaviorGraph(_observer);

_scanningOperations.Each(x => x(_types));

// Service registrations from imports
allServiceRegistrations().Each(x => x(graph.Services));

Expand Down
1 change: 1 addition & 0 deletions src/FubuMVC.Tests/FubuMVC.Tests.csproj
Expand Up @@ -175,6 +175,7 @@
<Compile Include="Commands\usage_graph_smoke_tester.cs" />
<Compile Include="ConnegAttributeTester.cs" />
<Compile Include="FubuApplicationTester.cs" />
<Compile Include="FubuRegistryWithTypesTester.cs" />
<Compile Include="Http\AspNet\AspNetModelBindingTester.cs" />
<Compile Include="Http\AspNet\ASPNetObjectConversionFamilyTester.cs" />
<Compile Include="Http\AspNet\AspNetServiceArgumentsTester.cs" />
Expand Down
39 changes: 39 additions & 0 deletions src/FubuMVC.Tests/FubuRegistryWithTypesTester.cs
@@ -0,0 +1,39 @@
using FubuMVC.Core;
using FubuMVC.Core.Registration.ObjectGraph;
using NUnit.Framework;
using FubuCore;
using System.Collections.Generic;
using System.Linq;
using FubuTestingSupport;

namespace FubuMVC.Tests
{
[TestFixture]
public class FubuRegistryWithTypesTester
{

[Test]
public void smoke_test_the_with_types()
{
var registry = new FubuRegistry();
registry.Applies.ToThisAssembly();
registry.WithTypes(types =>
{
types.TypesMatching(x => x.IsConcreteTypeOf<MyInterface>()).Each(type =>
{
registry.Services(s => s.AddService(typeof(MyInterface), new ObjectDef(type)));
});
});

registry.BuildGraph().Services.ServicesFor<MyInterface>()
.Single().Type.ShouldEqual(typeof (MyConcreteClass));
}

public interface MyInterface{}

public class MyConcreteClass : MyInterface
{

}
}
}

0 comments on commit a316e6a

Please sign in to comment.