Open 5ko100yanov opened 2 weeks ago
@hassanhabib ^^^
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
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:
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.