protected override void Load(ContainerBuilder builder) { builder.Register(db => { var ctx = new DefaultDataContext(); return(ctx); }) .InstancePerLifetimeScope() .AsSelf() .OnActivated(x => { }) .OnRelease(db => { //if (db.ChangeTracker.HasChanges() == false) //{ // db.Dispose(); // return; //} //var entitiesErrors = db.GetValidationErrors().ToList(); //if (entitiesErrors.Count > 0) //{ // //TODO logged // //foreach (var e in entitiesErrors) // //{ // // LogWriter.Default.WriteError(e); // //} // db.Dispose(); //} //else //{ // db.SaveChanges(); //} }); }
private bool disposedValue = false; // 要检测冗余调用 protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: 释放托管状态(托管对象)。 if (_context != null) { _context.Dispose(); _context = null; } } // TODO: 释放未托管的资源(未托管的对象)并在以下内容中替代终结器。 // TODO: 将大型字段设置为 null。 disposedValue = true; } }
public UnitOfWork(DefaultDataContext context) { _context = context; }