Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Created October 16, 2011 03:01
Show Gist options
  • Save jmarnold/1290451 to your computer and use it in GitHub Desktop.
Save jmarnold/1290451 to your computer and use it in GitHub Desktop.
Action Discovery
public class CreateEntityAction<TEntity>
where TEntity : IDomainEntity
{
public CommandResult<TEntity> Execute(CreateEntityModel<TEntity> input)
{
// do generic stuff
}
}
public class CreateEntityActionSource : IActionSource
{
public IEnumerable<ActionCall> FindActions(TypePool types)
{
var entities = // get the types from a scan or something conventional
entities
.Select(entity => {
var handlerType = typeof(CreateEntityAction<>).MakeGenericType(entity);
return new ActionCall(handlerType, handlerType.GetMethod("Execute", BindingFlags.Public | BindingFlags.Instance));
});
}
}
public interface IActionSource
{
IEnumerable<ActionCall> FindActions(TypePool types);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment