Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created February 10, 2011 04:33
Show Gist options
  • Save jmarnold/819950 to your computer and use it in GitHub Desktop.
Save jmarnold/819950 to your computer and use it in GitHub Desktop.
public interface IPartialDecorator<T>
where T : class
{
T Enrich(T target);
}
public class PartialAction<T>
where T : class
{
private readonly IContainer _container;
public PartialAction(IContainer container)
{
_container = container;
}
public T Execute(T target)
{
_container
.GetAllInstances<IPartialDecorator<T>>()
.Each(d =>
{
// allow classes to hook in and build up model properties
target = d.Enrich(target);
});
return target;
}
}
// hook this up with an Actions.FindWith<PartialActionSource>() in your FubuRegistry
public class PartialActionSource : IActionSource
{
public IEnumerable<ActionCall> FindActions(TypePool types)
{
return types
.TypesMatching(t => t.HasAttribute<PartialModelAttribute>() && !t.GetGenericArguments().Any())
.Select(m =>
{
var actionType = typeof(PartialAction<>).MakeGenericType(m);
return new ActionCall(actionType, actionType.GetExecuteMethod()); // just grabs the method named "Execute"
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment