Closed jasonlaw closed 3 years ago
well, that's a long read, and I'm not sure what the problem is in general. I would suggest for simplicity just avoid DI completely, do not inject EntityApp, just declare the singleton of your CustomEntityApp as a static field Instance on the CustomEntityApp itself and assign it in constoructor the entity app. Then it is available everywhere. You do not need to share OperationContext globally (but you can); just create the context when the scheduled task wakes up and needs access to the database. Or just OpenSession from the app instance, why you need to do OpContext explicitly?
Ahh...I think I got confused before.. The fact that I have the OpContext for free in controller (I pass in the OpContext to module method for db access), I was wondering how should I get it when the scheduled task run, totally forgot about we can create operation context from the global static entity app. Thank you for your time for this, really appreciate it!
Hi @rivantsov,
I need to perform some backend schedule task that required database access. For now, I am trying with a package FluentScheduler.
However, I am not quite sure how to make my job Vita OperationContext aware. Here is one reference for how the DI works with FluentScheduler. https://github.com/fluentscheduler/FluentScheduler/issues/180#issuecomment-408715307
Really appreciate your advice on this.
Thanks.