IOperationInvoker怎么样?
public class NHibernateOperationInvoker : IOperationInvoker {
private readonly IOperationInvoker _invoker;
private readonly String _operationName;
public NHibernateOperationInvoker(IOperationInvoker invoker, String operationName) {
_invoker = invoker;
_operationName = operationName;
}
public Object[] AllocateInputs() {
return _invoker.AllocateInputs();
}
public Object Invoke(Object instance, Object[] inputs, out Object[] outputs) {
using (var context = NHibernateContext.CreateNew()) {
try {
var result = _invoker.Invoke(instance, inputs, out outputs);
context.Commit();
return result;
} catch(Exception ex) {
Debug.Fail("Operation " + _operationName + " failed with " + ex.Message);
}
}
}
public IAsyncResult InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state) {
throw new NotImplementedException("NHibernateOperationInvoker.InvokeBegin");
}
public Object InvokeEnd(Object instance, out Object[] outputs, IAsyncResult result) {
throw new NotImplementedException("NHibernateOperationInvoker.InvokeEnd");
}
public Boolean IsSynchronous {
get { return true; }
}
}
这是使用IOperationBehavior附加的dispatchOperation.Invoker = new NHibernateOperationInvoker(dispatchOperation.Invoker, dispatchOperation.Name);