Fork me on GitHub

Build Plans Edit on GitHub


StructureMap 3.0 introduced the concept of the "Build Plan." The build plan is a textual representation of exactly how StructureMap will build a given Instance, including:

  1. What constructor function, if any, StructureMap is going to use for a concrete type
  2. How it is resolving the constructor dependencies in a recursive fashion
  3. Which setter properties for a concrete type receive dependencies and how those setter dependencies are built
  4. The lifecycle used for the Instance
  5. All interceptors applied to the Instance
  6. Explicitly configured inline dependencies
  7. Description of any Lambda or Func<T> that is used to construct the Instance object

To retrieve the build plan for a configured Instance, use the queryable Container.Model to find the configured Instance and call DescribeBuildPlan(int maxDepth) to get the textual report as shown in this sample below:


var container = Container.For<VisualizationRegistry>();

var description = container.Model.For<IDevice>().Default
    .DescribeBuildPlan();

Debug.WriteLine(description);

The result of the code above is this textual representation of how StructureMap will build and/or resolve the default of the IDevice plugin type:

PluginType: StructureMap.Testing.Diagnostics.IDevice
Lifecycle: Transient
Decorator --> FuncInterceptor of StructureMap.Testing.Diagnostics.IDevice: new DeviceDecorator(IDevice)
Decorator --> Decorator of type StructureMap.Testing.Diagnostics.CrazyDecorator
    new CrazyDecorator(IDevice, IEngine, IFoo)
      ┣ IDevice = The inner IDevice
      ┃ ┗ new DefaultDevice()
      ┣ IEngine = **Default**
      ┗ IFoo = **Default**
      

For another example, you can retrieve the build plan for a named instance of a certain build plan with this code:


var description = theContainer.Model.For<IDevice>()
    .Find("A")
    .DescribeBuildPlan();

See Using the Container Model for more information on using Container.Model.

You can find many more examples of finding the build plan description from Container.Model from the unit tests in the StructureMap codebase.