Created
July 3, 2010 13:39
-
-
Save CoreyKaylor/462573 to your computer and use it in GitHub Desktop.
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 DependencyWrapper : Wrapper | |
{ | |
private readonly object dependency; | |
public DependencyWrapper(Type behaviorType, object dependency) : base(behaviorType) | |
{ | |
this.dependency = dependency; | |
} | |
protected override FubuMVC.Core.Registration.ObjectGraph.ObjectDef buildObjectDef() | |
{ | |
var objectDef = base.buildObjectDef(); | |
objectDef.Child(dependency.GetType(), dependency); | |
return objectDef; | |
} | |
} |
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 static PoliciesExpression WrapBehaviorChainsWith<T, TV>(this PoliciesExpression policiesExpression, Func<ActionCall, TV> configurationAction) where T : IActionBehavior | |
{ | |
policiesExpression.Add(new LambdaConfigurationAction(graph => | |
{ | |
graph.Actions().Each(call => | |
{ | |
call.AddAfter(new DependencyWrapper(typeof(T), configurationAction(call))); | |
}); | |
})); | |
return policiesExpression; | |
} |
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
Policies | |
.WrapBehaviorChainsWith<TransactionBehavior, TransactionSettings>(call => | |
{ | |
object[] transactionSettingsAttributes = | |
call.Method.GetCustomAttributes(typeof (TransactionSettingsAttribute), true); | |
if (transactionSettingsAttributes.Length == 1) | |
{ | |
var useTransactionAttribute = | |
(TransactionSettingsAttribute) transactionSettingsAttributes[0]; | |
return new TransactionSettings | |
{ | |
Timeout = useTransactionAttribute.Timeout, | |
IsolationLevel = useTransactionAttribute.IsolationLevel, | |
Options = useTransactionAttribute.TransactionScopeOption | |
}; | |
} | |
return new TransactionSettings | |
{ | |
Timeout = TimeSpan.FromSeconds(30), | |
IsolationLevel = IsolationLevel.ReadCommitted, | |
Options = TransactionScopeOption.Required | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment