namespace IoC.Tests.UsageScenarios { using System.Collections.Generic; using Shouldly; using Xunit; public class Tracing { [Fact] public void Run() { // $visible=true // $tag=5 Advanced // $priority=08 // $description=Tracing // $header=Tracing allows to explore most aspects of container behavior: creating and removing child containers, adding and removing bindings, compiling instance factories. // { var traceMessages = new List(); // This block is just to mark the scope for "using" statements { // Create and configure a root container using var rootContainer = Container .Create("root") // Aggregate trace messages to the list 'traceMessages' .Trace(e => traceMessages.Add(e.Message)) .Container; // Create and configure a parent container using var parentContainer = rootContainer .Create("parent") .Bind().To(ctx => new Dependency()) .Container; // Create and configure a child container using var childContainer = parentContainer .Create("child") .Bind>().To>() .Container; childContainer.Resolve>(); } // All containers were disposed of here traceMessages.Count.ShouldBe(8); // } } } }