I created a pipeline with only one block, on the block implementation I get a Policy
object, something like this:
var testPolicy = context.GetPolicy<TestPolicy>();
Condition.Requires(testPolicy).IsNotNull("testPolicy is missing");
Condition.Requires(testPolicy.Test).IsNotNullOrEmpty("The testPolicy.Test can not be null or empty");
I need to run this pipeline only once, since it will spin one thread that will be doing some work while the app is running, so that's why I'm trying to run it from the Startup class Configure method like this:
Task.Run(() => testPipeline.Run(string.Empty, NodeContext.GetPipelineContextOptions()));
But in this case the testPolicy.Test
won't be loaded properly, so the assertion will fail.
If I setup this pipeline to run as part of any existing one for example any of the carts pipeline it will properly load the testPolicy.Test
so it is not an issue with the policy setting on the environments json files or anything like that. My guess is that at that point (running from Startup class Configure method) the CommerceContext
or something else is not completely loaded/setup...?
Anyway, I guess the question really is, where can I start this pipeline so that it gets executed only once (as soon as the app starts) without any issue loading policy objects?