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:
- What constructor function, if any, StructureMap is going to use for a concrete type
- How it is resolving the constructor dependencies in a recursive fashion
- Which setter properties for a concrete type receive dependencies and how those setter dependencies are built
- The lifecycle used for the Instance
- All interceptors applied to the Instance
- Explicitly configured inline dependencies
- 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.