private static Func <DispatchMiddlewareContext, Func <Task>, Task> BeginMiddlewareScope(IServiceProvider serviceProvider)
        {
            return(async(context, next) =>
            {
                IOrchestrationScope scope = OrchestrationScope.GetOrCreateScope(
                    context.GetProperty <OrchestrationInstance>().InstanceId, serviceProvider);

                using (scope.Enter())
                {
                    await next().ConfigureAwait(false);
                }
            });
        }
Example #2
0
        /// <summary>
        /// Enters the scope identified by <paramref name="orchestrationInstanceId"/>.
        /// </summary>
        /// <param name="orchestrationInstanceId">The orchestration instance id. Not null or empty.</param>
        /// <returns>A disposalable that will exit the scope when disposed.</returns>
        public static IDisposable EnterScope(string orchestrationInstanceId)
        {
            IOrchestrationScope scope = GetScope(orchestrationInstanceId);

            return(scope?.Enter() ?? EmptyDisposable.Instance);
        }