Skip to content

Commit

Permalink
introduced IChainSource
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydmiller committed Mar 3, 2014
1 parent 0f8031e commit 0370d25
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 112 deletions.
7 changes: 3 additions & 4 deletions src/FubuMVC.Core/Configuration/BehaviorGraphBuilder.cs
Expand Up @@ -21,7 +21,7 @@ public static BehaviorGraph Import(FubuRegistry registry, BehaviorGraph parent)

config.RunActions(ConfigurationType.Settings, graph);

config.RunActions(ConfigurationType.Discovery, graph);
config.Sources.SelectMany(x => x.BuildChains(graph.Settings)).Each(chain => graph.AddChain(chain));

config.Imports.Each(import => {
graph.As<IChainImporter>().Import(import.BuildChains(graph));
Expand Down Expand Up @@ -55,8 +55,8 @@ public static BehaviorGraph Build(FubuRegistry registry)
.OfType<IServiceRegistration>()
.Each(x => x.Apply(graph.Services));

config.RunActions(ConfigurationType.Discovery, graph);

config.Sources.SelectMany(x => x.BuildChains(graph.Settings)).Each(chain => graph.AddChain(chain));

config.UniqueImports().Each(import => {
graph.As<IChainImporter>().Import(import.BuildChains(graph));
Expand Down Expand Up @@ -90,7 +90,6 @@ public static IEnumerable<string> ConfigurationOrder()
return new string[]
{
ConfigurationType.Settings,
ConfigurationType.Discovery,
ConfigurationType.Explicit,
ConfigurationType.Policy,
ConfigurationType.Attributes,
Expand Down
44 changes: 29 additions & 15 deletions src/FubuMVC.Core/Configuration/ConfigGraph.cs
@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Bottles;
using FubuCore.Reflection;
using FubuCore.Util;
using FubuMVC.Core.Diagnostics;
using FubuMVC.Core.Registration;

namespace FubuMVC.Core.Configuration
Expand All @@ -13,15 +15,33 @@ namespace FubuMVC.Core.Configuration
/// </summary>
public class ConfigGraph
{
private readonly Assembly _applicationAssembly;

private readonly Cache<string, ConfigurationActionSet> _configurations
= new Cache<string, ConfigurationActionSet>(x => new ConfigurationActionSet(x));

private readonly IList<RegistryImport> _imports = new List<RegistryImport>();
private readonly IList<ServiceRegistry> _services = new List<ServiceRegistry>();

public ConfigGraph()
private readonly ActionSourceAggregator _actionSourceAggregator;
private readonly IList<IChainSource> _sources = new List<IChainSource>();

public ConfigGraph(Assembly applicationAssembly)
{
_configurations[ConfigurationType.Discovery] = new ActionSourceConfigurationActionSet();
_applicationAssembly = applicationAssembly;
_actionSourceAggregator = new ActionSourceAggregator(_applicationAssembly);

_sources.Add(_actionSourceAggregator);

if (FubuMode.InDevelopment())
{
Add(new RegisterAbout());
}
}

public Assembly ApplicationAssembly
{
get { return _applicationAssembly; }
}

public IEnumerable<RegistryImport> Imports
Expand Down Expand Up @@ -105,7 +125,10 @@ public void Add(IConfigurationAction action, string configurationType = null)
_configurations[type].Fill(action);
}


public void Add(IChainSource source)
{
_sources.Add(source);
}

public void Add(ServiceRegistry services)
{
Expand All @@ -114,7 +137,7 @@ public void Add(ServiceRegistry services)

public void Add(IActionSource source)
{
Add(new ActionSourceRunner(source), ConfigurationType.Discovery);
_actionSourceAggregator.Add(source);
}

public void RegisterServices(ServiceGraph services)
Expand Down Expand Up @@ -151,18 +174,9 @@ public static string DetermineConfigurationType(IConfigurationAction action)
return null;
}

/// <summary>
/// Honestly, this is 50% a HACK. This just gives ConfigGraph a chance to apply the default endpoint action source
/// if the FubuRegistry doesn't already have any
/// </summary>
public void Seal()
public IEnumerable<IChainSource> Sources
{
var actions = _configurations[ConfigurationType.Discovery].Actions;

if (!actions.Any(x => x is ActionSourceRunner))
{
Add(new EndpointActionSource());
}
get { return _sources; }
}
}
}
18 changes: 0 additions & 18 deletions src/FubuMVC.Core/Configuration/ConfigurationActionSet.cs
Expand Up @@ -63,22 +63,4 @@ public virtual void RunActions(BehaviorGraph graph)
}
}

public class ActionSourceConfigurationActionSet : ConfigurationActionSet
{
public ActionSourceConfigurationActionSet() : base(Core.ConfigurationType.Discovery)
{
}

public override void RunActions(BehaviorGraph graph)
{
if (!Actions.OfType<ActionSourceRunner>().Any())
{
new ActionSourceRunner(new EndpointActionSource()).Configure(graph);
}



base.RunActions(graph);
}
}
}
11 changes: 0 additions & 11 deletions src/FubuMVC.Core/Configuration/DefaultConfigurationPack.cs
@@ -1,24 +1,15 @@
using FubuMVC.Core.Ajax;
using FubuMVC.Core.Caching;
using FubuMVC.Core.Diagnostics;
using FubuMVC.Core.Registration.Conventions;
using FubuMVC.Core.Registration.Nodes;
using FubuMVC.Core.Resources.Conneg;
using FubuMVC.Core.Resources.PathBased;
using FubuMVC.Core.Security;

namespace FubuMVC.Core.Configuration
{
public class DefaultConfigurationPack : ConfigurationPack
{
public DefaultConfigurationPack()
{
For(ConfigurationType.Discovery);
if (FubuMode.InDevelopment())
{
Add<RegisterAbout>();
}

For(ConfigurationType.Attributes);
Add<UrlPatternAttributeOnViewModelPolicy>();
Add<ModifyChainAttributeConvention>();
Expand Down Expand Up @@ -49,7 +40,5 @@ public DefaultConfigurationPack()
WhatMustBeAfter = node => node is OutputNode
});
}


}
}
Expand Up @@ -7,7 +7,7 @@ public class DiscoveryActionsConfigurationPack : ConfigurationPack
{
public DiscoveryActionsConfigurationPack()
{
For(ConfigurationType.Discovery);
For(ConfigurationType.Explicit);

Add<PartialOnlyConvention>();
Add<RouteDetermination>();
Expand Down
1 change: 0 additions & 1 deletion src/FubuMVC.Core/ConfigurationType.cs
Expand Up @@ -6,7 +6,6 @@ namespace FubuMVC.Core
public static class ConfigurationType
{
public const string Settings = "Settings";
public const string Discovery = "Discovery";
public const string Explicit = "Explicit";
public const string Policy = "Policy";
public const string Reordering = "Reordering";
Expand Down
17 changes: 9 additions & 8 deletions src/FubuMVC.Core/Diagnostics/RegisterAbout.cs
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using FubuCore.Descriptions;
using FubuMVC.Core.Registration;
using FubuMVC.Core.Registration.Nodes;
Expand All @@ -6,32 +7,32 @@
namespace FubuMVC.Core.Diagnostics
{
[Title("Register the _about endpoint")]
public class RegisterAbout : IConfigurationAction
public class RegisterAbout : IChainSource
{
public void Configure(BehaviorGraph graph)
public IEnumerable<BehaviorChain> BuildChains(SettingsCollection settings)
{
addAboutEndpoint(graph);
addReloadedEndpoint(graph);
yield return addAboutEndpoint();
yield return addReloadedEndpoint();
}

private static void addAboutEndpoint(BehaviorGraph graph)
private static BehaviorChain addAboutEndpoint()
{
var action = ActionCall.For<AboutEndpoint>(x => x.get__about());
var chain = new BehaviorChain();
chain.AddToEnd(action);
chain.Route = new RouteDefinition("_about");

graph.AddChain(chain);
return chain;
}

private static void addReloadedEndpoint(BehaviorGraph graph)
private static BehaviorChain addReloadedEndpoint()
{
var action = ActionCall.For<AboutEndpoint>(x => x.get__loaded());
var chain = new BehaviorChain();
chain.AddToEnd(action);
chain.Route = new RouteDefinition("_loaded");

graph.AddChain(chain);
return chain;
}
}
}
3 changes: 0 additions & 3 deletions src/FubuMVC.Core/FubuApplication.cs
Expand Up @@ -152,9 +152,6 @@ public FubuRuntime Bootstrap()
// container facility has to be spun up here
var containerFacility = _facility.Value;
// Need to do this to make the provenance for bottles come out right
_registry.Value.Config.Seal();
applyFubuExtensionsFromPackages();
graph = buildBehaviorGraph();
Expand Down
1 change: 0 additions & 1 deletion src/FubuMVC.Core/FubuMVC.Core.csproj
Expand Up @@ -346,7 +346,6 @@
<Compile Include="Http\NulloHttpResponse.cs" />
<Compile Include="Http\RequestDataSource.cs" />
<Compile Include="Packaging\ContentOnlyPackageInfo.cs" />
<Compile Include="Registration\BehaviorAggregator.cs" />
<Compile Include="Registration\Nodes\ActionCallBase.cs" />
<Compile Include="Registration\Nodes\BehaviorNode.ObjectDef.cs" />
<Compile Include="Registration\Nodes\Process.cs" />
Expand Down
4 changes: 3 additions & 1 deletion src/FubuMVC.Core/FubuRegistry.cs
Expand Up @@ -28,7 +28,7 @@ public partial class FubuRegistry
{
private readonly IList<Type> _importedTypes = new List<Type>();
private readonly Assembly _applicationAssembly;
private readonly ConfigGraph _config = new ConfigGraph();
private readonly ConfigGraph _config;

public FubuRegistry()
{
Expand All @@ -41,6 +41,8 @@ public FubuRegistry()
{
_applicationAssembly = type.Assembly;
}

_config = new ConfigGraph(_applicationAssembly);
}

public FubuRegistry(Action<FubuRegistry> configure) : this()
Expand Down
37 changes: 0 additions & 37 deletions src/FubuMVC.Core/Registration/BehaviorAggregator.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/FubuMVC.Core/Registration/BehaviorGraph.cs
Expand Up @@ -59,6 +59,7 @@ public BehaviorGraph()
_services.AddService<ITypeResolver>(TypeResolver);
}

[MarkedForTermination("I think this will be unnecessary in 2.0")]
public Assembly ApplicationAssembly { get; set; }

public SettingsCollection Settings
Expand Down
@@ -1,14 +1,14 @@
namespace FubuMVC.Core.Registration.Conventions
{
[Policy]
[ConfigurationType(ConfigurationType.Explicit)]
public class PartialOnlyConvention : Policy
{
public const string Partial = "Partial";

public PartialOnlyConvention()
{
Where.AnyActionMatches(call => call.Method.Name.EndsWith("Partial"));
ModifyBy(chain => chain.IsPartialOnly = true, configurationType: ConfigurationType.Policy);
ModifyBy(chain => chain.IsPartialOnly = true, configurationType: ConfigurationType.Explicit);
}
}
}
47 changes: 47 additions & 0 deletions src/FubuMVC.Core/Registration/IActionSource.cs
Expand Up @@ -13,4 +13,51 @@ public interface IActionSource
{
IEnumerable<ActionCall> FindActions(Assembly applicationAssembly);
}

public interface IChainSource
{
IEnumerable<BehaviorChain> BuildChains(SettingsCollection settings);
}

public class ActionSourceAggregator : IChainSource
{
private readonly Assembly _applicationAssembly;
private readonly IList<IActionSource> _sources = new List<IActionSource>();

public ActionSourceAggregator(Assembly applicationAssembly)
{
_applicationAssembly = applicationAssembly;
}

public IEnumerable<BehaviorChain> BuildChains(SettingsCollection settings)
{
var sources = _sources.Any() ? _sources : new IActionSource[] {new EndpointActionSource()};

var actions = sources.SelectMany(x => x.FindActions(_applicationAssembly))
.Distinct();

foreach (var action in actions)
{
var chain = new BehaviorChain();
chain.AddToEnd(action);

yield return chain;
}
}

public void Add(IActionSource source)
{
_sources.Add(source);
}

public IEnumerable<IActionSource> Sources
{
get { return _sources; }
}

public Assembly ApplicationAssembly
{
get { return _applicationAssembly; }
}
}
}

0 comments on commit 0370d25

Please sign in to comment.