Skip to content

Container configuration

Peter Csajtai edited this page Jul 25, 2018 · 30 revisions

When you are creating a new instance of Stashbox you can use an action delegate to customize it e.g.:

var container = new Stashbox(config => config
	.WithCircularDependencyTracking()
	.WithCircularDependencyWithLazy()
	.WithConstructorSelectionRule(Rules.ConstructorSelection.PreferLeastParameters)
	//etc...);

The re-configuration of the container also supported by calling the container.Configure(...) method.

Options available

  • WithDisposableTransientTracking() - Enables the tracking of disposable transient objects.
  • WithCircularDependencyTracking() - Enables the circular dependency tracking.
  • WithUniqueRegistrationIdentifiers() - Enables the unique registration identifier generation, it allows multiple services registered with the same implementation types without naming.
  • WithCircularDependencyWithLazy() - Allows circular dependencies through Lazy<> objects.
  • WithOptionalAndDefaultValueInjection() - Enables the optional and default value injection.
  • WithUnknownTypeResolution() - When the container finds an unknown but a resolvable type (not an interface, abstract or sealed class), it'll try to register that type and then resolve it. You can also use a configurator delegate to control how the unknown type registrations should behave e.g: config.WithUnknownTypeResolution(context => context.AsImplementedTypes())
  • WithMemberInjectionWithoutAnnotation(...) - Enables the auto member injection without attributes.
    • PropertiesWithPublicSetter - With this flag the container will perform auto injection on properties with public setters.
    • PropertiesWithLimitedAccess - With this flag the container will perform auto injection on properties even when they don't have a public setter.
    • PrivateFields - With this flag the container will perform auto injection on private fields too.
  • WithConstructorSelectionRule(...) - Sets the constructor selection rule.
    • PreferMostParameters - Prefers the constructor which has the longest parameter list.
    • PreferLeastParameters - Prefers the constructor which has the shortest parameter list.