Unless designated otherwise, StructureMap uses Transient as the default scope for all configured Instance's.
StructureMap's default scoping to Transient is not a universal assumption across IoC containers in .Net. Be careful with this if you are coming to StructureMap from tools that choose Singleton as their default scope.
The resolution of the lifecycle for any given Instance is to check:
- Use the explicitly configured lifecycle for the Instance
- If no lifecycle is configured for the Instance, use the explicitly configured lifecycle for the Plugin Type
- If no lifecycle is configured for either the Instance or the Plugin Type, use the default Transient lifecycle
The lifecycle precedence rules and the syntax for configuring object lifecycles are shown below:
<[sample:lifecycle-rules]>
New in StructureMap 4.0 are some simple attributes to mark either a complete Plugin Type or a single Instance as either a singleton or using the always unique lifecycle:
The usage is shown below:
<[sample:using-lifecycle-attributes]>
See <[linkto:registration/attributes]> for information about adding your own custom attibutes for other lifecycles.