Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BROKERS: StorageBroker contains logic against The Standard #191

Open
5ko100yanov opened this issue Sep 19, 2024 · 3 comments
Open

BROKERS: StorageBroker contains logic against The Standard #191

5ko100yanov opened this issue Sep 19, 2024 · 3 comments

Comments

@5ko100yanov
Copy link

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.

@5ko100yanov 5ko100yanov changed the title StorageBroker contains logic against The Standard BROKERS: StorageBroker contains logic against The Standard Sep 19, 2024
@cjdutoit
Copy link
Contributor

@hassanhabib ^^^

@glhays
Copy link
Member

glhays commented Oct 6, 2024

@glhays
Copy link
Member

glhays commented Oct 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants