public async Task <HttpResponseMessage> ExecuteActionFilterAsync(HttpActionContext actionContext, CancellationToken cancellationToken, Func <Task <HttpResponseMessage> > continuation) { /* * var dataSessionHolder = (DataSessionHolder)actionContext.Request.GetDependencyScope().GetService(typeof(DataSessionHolder)); * if (dataSessionHolder == null) * { * throw new DataAccessException($"The {typeof(DataSessionHolder).Name} could not retrieved from the request's IDependencyScope. Check your DI configuration and make sure the holder is registered properly."); * } */ var dataSession = DataSession.Current(DataName); if (dataSession == null) { throw new DataAccessException("The DataSession could not retrieved from the current context. Check your configuration and make sure the holder is registered properly."); } Log.Debug("Creating unit of work."); using (var unitOfWork = dataSession.CreateUnitOfWork()) { unitOfWork.AutoCommit = false; var ret = await continuation(); Log.Debug("Commiting unit of work."); unitOfWork.Commit(); return(ret); } }
/// <summary> /// Retrieve the <see cref="IDataSession"/> from the <see cref="IDataSessionAware"/>. /// </summary> /// <param name="dataSessionAware"></param> /// <returns></returns> public static IDataSession GetDataSession(this IDataSessionAware dataSessionAware) { var dataSession = DataSession.Current(dataSessionAware.DataName); return(dataSession); }