NickStrupat / EntityFramework.Triggers

Adds events for entity inserting, inserted, updating, updated, deleting, and deleted
MIT License
373 stars 46 forks source link

question re async #65

Open ericsampson opened 7 months ago

ericsampson commented 7 months ago

Hi, love this library!

What's the right way to use async code in the trigger body? Like this pseudo-code example:

configure.Triggers<Order, dbContext>().Inserted
                    .Add<(IEmitter Emitter, IDepotOrderRepository OrderRepository)>(
                    async entry =>
                    {
                        var foo = await OrderRepository.DoSomething();
                        await Emitter.Emit(foo);
                        Console.WriteLine($"The value of foo is: {foo}");
                     }
);
NickStrupat commented 7 months ago

That's pretty much it, yep. It's missing CancellationToken support for now.

ericsampson commented 2 months ago

So the issue I'm getting is coming from SimpleInjector. Any thoughts on how I can resolve this? Cheers!

SimpleInjector.ActivationException: DepotOrderRepository is registered using the 'Async Scoped' lifestyle, but the instance is requested outside the context of an active (Async Scoped) scope.