silverback icon indicating copy to clipboard operation
silverback copied to clipboard

Is it possible to use outbox without overwriting SaveChanges

Open RomanOlegovich opened this issue 2 years ago • 2 comments

There are cron jobs, which are produce events. So I want to push event into outobox without using of DbContext (just to handle if queue doesn't work). Does Silverback help to me?)

RomanOlegovich avatar Apr 28 '22 07:04 RomanOlegovich

  1. SetUp outbox DbContext and ProduceToOutBoxTable
  2. Call publisher.Push()
  3. What I should do to send events to outbox?

RomanOlegovich avatar Apr 28 '22 07:04 RomanOlegovich

Overriding the SaveChanges method is necessary only to automatically publish the domain events embedded in the models (aggregates) being saved. The outbox works independently of that and you just need to call a SaveChanges after you published the messages in order for them to be persisted.

await publisher.PublishAsync(message1);
await publisher.PublishAsync(message2);
await publisher.PublishAsync(message3);

await dbContext.SaveChangesAsync();

Using the outbox without the DbContext altogether is not possible. Currently, the only way to write to the database is through a DbContext. Again, this will change in Silverback 4. :wink:

BEagle1984 avatar Apr 28 '22 08:04 BEagle1984