The-Standard-Organization / GitFyle.Core.Api

15 stars 15 forks source link

BROKERS: StorageBroker contains logic against The Standard #191

Open 5ko100yanov opened 2 weeks ago

5ko100yanov commented 2 weeks ago

According to The Standard, logic doesn't live at the broker because you can't test-drive it.

The existing StorageBroker methods have logic. Sequencing is a kind of logic too, try-catch-finally as well.

Beeing untested, the StorageBroker has a hidden bug. Lets dig into:

private async ValueTask<T> UpdateAsync<T>(T @object)
{
    this.Entry(@object).State = EntityState.Modified;
    await this.SaveChangesAsync();
    DetachEntity(@object);

    return @object;
}

If SaveChangesAsync fails, @object will remain Attached and tracked as Modified.

Any subsequent call to a Broker method will update the @object from the failed call.

cjdutoit commented 2 weeks ago

@hassanhabib ^^^

glhays commented 1 day ago

@hassanhabib @cjdutoit

https://www.nuget.org/packages/STX.EFCore.Client

Christo's offering.

glhays commented 1 day ago

Just as reference.


  public partial class StorageBroker : EFxceptionsContext, IStorageBroker
  {
      private readonly IConfiguration configuration;
      private readonly IEFCoreClient efCoreClient;

      public StorageBroker(IConfiguration configuration)
      {
          this.configuration = configuration;
          this.Database.Migrate();
          this.efCoreClient = new EFCoreClient(this);
      }

      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
          AddConfigurations(modelBuilder);
      }

      . . .

      private async ValueTask<T> InsertAsync<T>(T @object) where T : class =>
          await efCoreClient.InsertAsync(@object);

      private async ValueTask<IQueryable<T>> SelectAllAsync<T>() where T : class =>
          await efCoreClient.SelectAllAsync<T>();

      private async ValueTask<T> SelectAsync<T>(params object[] @objectIds) where T : class =>
          await efCoreClient.SelectAsync<T>(@objectIds);

      private async ValueTask<T> UpdateAsync<T>(T @object) where T : class =>
          await efCoreClient.UpdateAsync(@object);

      private async ValueTask<T> DeleteAsync<T>(T @object) where T : class =>
          await efCoreClient.UpdateAsync(@object);

      private async ValueTask BulkInsertAsync<T>(IEnumerable<T> objects) where T : class =>
          await efCoreClient.BulkInsertAsync<T>(objects);

      private async ValueTask BulkUpdateAsync<T>(IEnumerable<T> objects) where T : class =>
          await efCoreClient.BulkUpdateAsync<T>(objects);

      private async ValueTask BulkDeleteAsync<T>(IEnumerable<T> objects) where T : class =>
          await efCoreClient.BulkDeleteAsync<T>(objects);
  }

https://github.com/cjdutoit/STX.EFCore.Client https://www.nuget.org/packages/STX.EFCore.Client