public void Scoped() { var firstScope = _dependencyProvider.CreateScope(); var firstEmitter = firstScope.GetRequiredService <Emitter>(); var secondScope = _dependencyProvider.CreateScope(); var secondEmitter = secondScope.GetRequiredService <Emitter>(); firstEmitter.Should().NotBe(secondEmitter); }
public async Task ExecutedMultiThreadingWithDifferentScopes(Boo[] boos) { var commands = boos .Select(b => new Command { Id = b.Id, Int = b.Int }) .ToArray(); await RunTasks(commands, command => { using var scope = _dependencyProvider.CreateScope(); var scopeEmitter = scope.GetRequiredService <Emitter>(); return(scopeEmitter.Execute(command)); }); foreach (var command in commands) { command.Measured.Should().BeTrue(); command.PreProcessed.Should().BeTrue(); command.PostProcessed.Should().BeTrue(); _repository.Verify(repository => repository .AddElement(It.Is <Boo>(boo => boo.Id == command.Id && boo.Int == command.Int))); } }
public string Mixed_Velo() { using (var scope = _veloContainerMixed.CreateScope()) { var controller = scope.GetService <SomethingController>(); var dataService = scope.GetService <IFooService>(); var userService = scope.GetService <IBooService>(); return(controller.Name + dataService.Name + userService.Name); } }
public async Task DisposedAfterCloseScope() { NotificationPipeline <Notification> pipeline; using (var scope = _provider.CreateScope()) { pipeline = scope.GetRequiredService <NotificationPipeline <Notification> >(); } await Assert.ThrowsAsync <NullReferenceException>( () => pipeline.Publish(It.IsAny <Notification>(), CancellationToken.None)); }
private async Task HandleRequest(HttpListenerContext context, IHttpRequestHandler handler) { using var cancellationSource = new CancellationTokenSource(); using var dependencyScope = _dependencyProvider.CreateScope(); try { await handler.Handle(context, cancellationSource.Token); } catch (Exception) { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; } }
public async Task PublishedMultiThreadingWithDifferentScopes(Notification[] notifications) { await RunTasks(notifications, notification => { notification.StopPropagation = false; using var scope = _dependencyProvider.CreateScope(); var scopeEmitter = scope.GetRequiredService <Emitter>(); return(scopeEmitter.Publish(notification)); }); foreach (var notification in notifications) { _fooRepository.Verify(repository => repository .AddElement(It.Is <Foo>(foo => foo.Int == notification.Id))); } }
public async Task AskMultiThreadingWithDifferentScopes(Boo[] boos) { var queries = boos.Select(b => new Query(b.Id)).ToArray(); var results = await RunTasks(queries, query => { using var scope = _dependencyProvider.CreateScope(); var scopeEmitter = scope.GetRequiredService <Emitter>(); return(scopeEmitter.Ask(query)); }); foreach (var query in queries) { query.PreProcessed.Should().BeTrue(); query.PostProcessed.Should().BeTrue(); _repository.Verify(repository => repository .GetElement(It.Is <int>(id => id == query.Id))); results.Should().Contain(b => b.Id == query.Id); } }