Open catsburg opened 2 years ago
Hi @catsburg, this is certainly a part of our plans myself & @IEvangelist where just chatting about it the other day. It might be required that we inject something other than IRepository<T>
to deal with batches as a batch can span multiple IItem
s and current the IRepository<T>
is scoped to one item in this libraries case, but I like the look of your API it certainly could be done and could ease some of the error handling when a batch fails. Like the idea 😃
Having a look at this and found this example, the question here is how can we make this API they already offer easier to use, just an open question, see here.
@mumby0168 Glad to hear that it's part of your plans!
Just to share some thoughts on this:
IRepository<T>
s might cause the following problems:
IRepository<T>
s CAN use different containers. The only way to know for sure you're working with a single container, is when you have a single IRepository<T>
.IItem
IRepository<T>
level will work just fine for one-type-per-container uses cases, and works fine for multiple-types-per-container use cases as long as the transactions involve just the one item type.Hope this is useful! Pretty cool project you guys have, but unfortunately since we require transactions, we're not going to use it for now, and create our own Repositories instead .
- For the missing use case (multiple-types-per-container AND you want to do a transaction across multiple types): How relevant is this use case? Wouldn't there be something to say for IF you find yourself wanting to do this, you probably modeled your application poorly? Like for instance, you should denormalize further?
A transactional batch that supports multiple item types might allow this library to be used to follow the Transactional Outbox pattern described here, though it might be a little difficult modelling this with the current IRepository<T>
:
https://learn.microsoft.com/en-us/azure/architecture/databases/guide/transactional-outbox-cosmos
The repositories currently don't offer support for transactions (using TransactionalBatch), for use cases where a bunch of CRUD actions have to all succeed/fail together. If transactions are required, the only solution now is to implement a custom Repository, which kind of defeats the purpose of using this library.
It would be cool to be able to do something along the lines of:
await _repository.Batch(partitionKey).Create(item1).Replace(item2.Id, item2).ExecuteAsync();