Created
July 2, 2012 16:37
-
-
Save chadmyers/3034151 to your computer and use it in GitHub Desktop.
WrapIfFirstCallMatchesPolicy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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