public void CreatingAnInstanceByContainerIsComparablyFastAsInjectingDependenciesManually() { var manualInjectionStopWatch = new Stopwatch(); var containerStopWatch = new Stopwatch(); containerStopWatch.Start(); using (var container = CreateContainerWithRegisteredServices()) { containerStopWatch.Stop(); for (var i = 0; i < TryCount / TryCountChunk; i++) { manualInjectionStopWatch.Start(); for (var j = 0; j < TryCountChunk; j++) { using (var service = new RootServiceImplementation(CreateTestServiceDependencyManually())) { service.Use(); } } manualInjectionStopWatch.Stop(); containerStopWatch.Start(); for (var j = 0; j < TryCountChunk; j++) { using (container.Resolve <IRootService>(out var serviceFromContainer)) { serviceFromContainer.Use(); } } containerStopWatch.Stop(); } } var manualInjectionDuration = manualInjectionStopWatch.ElapsedMilliseconds; var containerDuration = containerStopWatch.ElapsedMilliseconds; var containerPerformancePercentage = (double)containerDuration / manualInjectionDuration * 100; TestContext.WriteLine($"Container performance: {containerPerformancePercentage:0}%"); Assert.Less(containerPerformancePercentage, 200); }
public void WarmUp() { using (var container = CreateContainerWithRegisteredServices()) { for (var i = 0; i < TryCount; i++) { using (var instance = new RootServiceImplementation(CreateTestServiceDependencyManually())) { instance.Use(); } using (container.Resolve <IRootService>(out var instance)) { instance.Use(); } } } }