public async Task MultipleScopes() { // Arrange var id = ThingyId.New; var pingId1 = PingId.New; var pingId2 = PingId.New; // Act using (var scopedResolver = Resolver.BeginScope()) { var commandBus = scopedResolver.Resolve <ICommandBus>(); await commandBus.PublishAsync( new ThingyPingCommand(id, pingId1)) .ConfigureAwait(false); } using (var scopedResolver = Resolver.BeginScope()) { var commandBus = scopedResolver.Resolve <ICommandBus>(); await commandBus.PublishAsync( new ThingyPingCommand(id, pingId2)) .ConfigureAwait(false); } // Assert var aggregate = await LoadAggregateAsync(id).ConfigureAwait(false); aggregate.PingsReceived.Should().BeEquivalentTo(new [] { pingId1, pingId2 }); }
public virtual void Test_Scoped() { // Arrange Registry.RegisterScoped <IMyClass, MyClass>(); IMyClass obj1, obj2, obj3, obj4; // Act (Getting two times to object) using (Resolver.BeginScope()) { obj1 = Resolver.Resolve <IMyClass>(); obj2 = Resolver.Resolve <IMyClass>(); } using (Resolver.BeginScope()) { obj3 = Resolver.Resolve <IMyClass>(); obj4 = Resolver.Resolve <IMyClass>(); } // Assert obj1.Should().NotBeNull(); obj2.Should().NotBeNull(); obj1.InstanceId.Should().NotBeEmpty(); obj2.InstanceId.Should().NotBeEmpty(); obj1.InstanceId.Should().Be(obj2.InstanceId); obj3.Should().NotBeNull(); obj4.Should().NotBeNull(); obj3.InstanceId.Should().NotBeEmpty(); obj4.InstanceId.Should().NotBeEmpty(); obj3.InstanceId.Should().Be(obj3.InstanceId); obj1.InstanceId.Should().NotBe(obj3.InstanceId); }
public virtual async Task QueryingUsesScopedDbContext() { using (var scope = Resolver.BeginScope()) { var dbContext = scope.Resolve <IScopedContext>(); var queryProcessor = scope.Resolve <IQueryProcessor>(); var result = await queryProcessor.ProcessAsync(new DbContextQuery(), CancellationToken.None); result.Should().Be(dbContext.Id); } }
public async Task PublishingStartAndCompleteTiggerEventsCompletesSaga() { // Arrange var thingyId = A <ThingyId>(); // Act using (var scope = Resolver.BeginScope()) { var commandBus = scope.Resolve <ICommandBus>(); await commandBus.PublishAsync(new ThingyRequestSagaStartCommand(thingyId), CancellationToken.None).ConfigureAwait(false); } using (var scope = Resolver.BeginScope()) { var commandBus = scope.Resolve <ICommandBus>(); await commandBus.PublishAsync(new ThingyRequestSagaCompleteCommand(thingyId), CancellationToken.None).ConfigureAwait(false); } // Assert var thingySaga = await LoadSagaAsync(thingyId).ConfigureAwait(false); thingySaga.State.Should().Be(SagaState.Completed); }