Skip to content

Instantly share code, notes, and snippets.

@CoreyKaylor
Created July 3, 2010 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CoreyKaylor/462573 to your computer and use it in GitHub Desktop.
Save CoreyKaylor/462573 to your computer and use it in GitHub Desktop.
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;
}
}
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;
}
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