Skip to content

Instantly share code, notes, and snippets.

@chadmyers
Created July 2, 2012 16:37
Show Gist options
  • Save chadmyers/3034151 to your computer and use it in GitHub Desktop.
Save chadmyers/3034151 to your computer and use it in GitHub Desktop.
WrapIfFirstCallMatchesPolicy
public class WrapIfFirstCallMatchesPolicy<TWrapperBehavior> : IConfigurationAction where TWrapperBehavior : IActionBehavior
{
readonly Func<ActionCall, bool> _filter;
public WrapIfFirstCallMatchesPolicy(Func<ActionCall, bool> filter )
{
_filter = filter;
}
public bool Matches(BehaviorChain chain)
{
var firstCall = chain.FirstCall();
return firstCall != null && _filter(firstCall);
}
public void Configure(BehaviorGraph graph)
{
graph.Behaviors.Where(Matches).Each(c => c.Prepend(Wrapper.For<TWrapperBehavior>()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment