我正在为我的DI使用MS WebAPI和Spring.NET,并使用Sprint.NET AOP将方法标记为事务性。Spring.NET AOP代理和MS WebAPI控制器
当我标志着一个“控制器”行动事务,我得到以下错误:
无法转换类型“CompositionAopProxy_13695853c76b40f8b9436e27afa947f0”的对象键入“TPMarketing.PayrollConsole.Web.Rest.Controllers.OrganisationsController”。在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor处的lambda_method(Closure,Object,Object [])\ r \ n处,“exceptionType”:“System.InvalidCastException”,“stackTrace” <> c_ DisplayClass13.b _c(Object instance,Object [] methodParameters)\ r \ n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance,Object [] arguments)\ r \ n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor。 <> C_ DisplayClass5.b 1-4(个)\ r \ n在System.Threading.Tasks.TaskHelpers.RunSynchronously [TResult(Func`1 FUNC键的CancellationToken的CancellationToken)
这是否意味着你不能使用代理服务器基于Web API控制器的基于Web的AOP?
(我有一个解决办法,我已经作出了自己的“交易”属性,从ActionFilterAttribute继承,只是在Web层使用)
感谢, 乔丹。所以这里
编辑... 我还没来得及检查Marijns建议下面呢,是我有兴趣的解决方法。这是来自我的Action Filter的代码体:(TransactionManager是Spring.NET IPlatformTransactionManager)。我仍然在我的服务层中使用普通的Spring.NET Transaction属性,并且这应该可以很好地发挥。
public override void OnActionExecuting(HttpActionContext actionContext)
{
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.ReadOnly = ReadOnly;
actionContext.Request.Properties[TRANSACTION_KEY] = TransactionManager.GetTransaction(def);
}
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
ITransactionStatus ts = actionExecutedContext.Request.Properties[TRANSACTION_KEY] as ITransactionStatus;
if (ts.RollbackOnly || actionExecutedContext.Exception != null)
{
TransactionManager.Rollback(ts);
}
else
{
TransactionManager.Commit(ts);
}
}
public bool ReadOnly { get; set; }
相关:http://stackoverflow.com/questions/4280143/asp-net-mvc-controller-declarative-aop-with-spring-net/4346791#4346791 – Marijn
我还没有尝试过使用web api,但前一段时间我已经发布了一个[详细回答这个](http://stackoverflow.com/a/9115510/322283),在“正常“asp.net MVC控制器。 – Marijn
好,非常感谢。 – gusgorman