Example #1
0
        public void CreateScope_Created()
        {
            // arrange
            string instanceId = Guid.NewGuid().ToString();

            // act
            IOrchestrationScope scope = OrchestrationScope.CreateScope(instanceId, GetServiceProvider());

            // assert
            scope.Should().NotBeNull();
            scope.ServiceProvider.Should().NotBeNull();
        }
        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 #3
0
        public void GetOrCreateScope_Found()
        {
            // arrange
            string instanceId = Guid.NewGuid().ToString();

            // act
            IOrchestrationScope first  = OrchestrationScope.CreateScope(instanceId, GetServiceProvider());
            IOrchestrationScope second = OrchestrationScope.GetOrCreateScope(instanceId, GetServiceProvider());

            // assert
            second.Should().NotBeNull();
            second.ServiceProvider.Should().NotBeNull();
            second.Should().BeSameAs(first);
        }
Example #4
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);
        }