Skip to content

Latest commit

 

History

History
27 lines (16 loc) · 1.31 KB

configuring-lifecycles.md

File metadata and controls

27 lines (16 loc) · 1.31 KB

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:

  1. Use the explicitly configured lifecycle for the Instance
  2. If no lifecycle is configured for the Instance, use the explicitly configured lifecycle for the Plugin Type
  3. 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]>

Using Attributes

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.