public static async ValueTask <EntityScope <TEntity> > Create( Func <Task <TEntity> > entityCreate, Func <TEntity, Task> entityDelete, ILog log) { var lifetime = new Lifetime(log); try { var entity = await entityCreate(); lifetime.Add(() => entityDelete(entity)); var result = new EntityScope <TEntity>(entity, lifetime); lifetime = null; return(result); } finally { if (lifetime != null) { await lifetime.DisposeAsync(); } } }
public ValueTask DisposeAsync() => lifetime.DisposeAsync();
public async Task DisposeAsync() => await lifetime.DisposeAsync();