public ActionResult <string> Get(CustomUnitOfWork customUnitofWork, int id) { //常规业务操作 customUnitofWork.StudentsRepository.Add(null); //可重用业务代码 也是 customUnitofWork.CustomUnifExtensionMethod(0, "test"); customUnitofWork.Commit();//第一次提交 return("value"); }
public ActionResult <IEnumerable <string> > Get(CustomUnitOfWork customUnitofWork, AnotherUnitOfWork antherUnit) { //常规业务操作 customUnitofWork.StudentsRepository.Add(null); //可重用业务代码 也是 customUnitofWork.CustomUnifExtensionMethod(0, "test"); antherUnit.StudentsRepository.Delete(null); //调用业务并不影响,可以自己决定commit时机 customUnitofWork.CustomUnifExtensionMethod(0, "test2"); antherUnit.Commit(); customUnitofWork.Commit();//第二次提交 return(new string[] { "value1", "value2" }); }
/// <summary> /// 这个里面放重用的工作单元方法 /// </summary> /// <param name=""></param> /// <param name="para1"></param> /// <param name="para2"></param> public static void CustomUnifExtensionMethod(this CustomUnitOfWork unit, int para1, string para2) { //reusable code 重用业务代码 }