Skip to content

Container configuration

Peter Csajtai edited this page Mar 14, 2017 · 30 revisions

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

var container = new Stashbox(config => config
	.WithCircularDependencyTracking()
	.WithCircularDependencyWithLazy()
	.WithEnumerableOrderRule(Rules.EnumerableOrder.PreserveOrder)
	//etc...);

The reconfiguration of the container also supported by calling the container.Configure(...) method.

Options available

  • WithDisposableTransientTracking() - Enables the tracking of disposable transient objects.
  • WithParentContainerResolution() - Enables the resolution through the parent container.
  • WithCircularDependencyTracking() - Enables the circular dependency tracking.
  • WithCircularDependencyWithLazy() - Allows circular dependencies through Lazy<> objects.
  • WithOptionalAndDefaultValueInjection() - Enables the optional and default value injection.
  • WithUnknownTypeResolution() - Enables the unknown type resolution.
  • WithMemberInjectionWithoutAnnotation(...) - Enables the member injection without annotation.
  • PropertiesWithPublicSetter - With this flag the container will perform auto injection on properties which has a public setter.
  • PropertiesWithLimitedAccess - With this flag the container will perform auto injection on properties which has a non public setter as well.
  • 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.
  • PreferLessParameters - Prefers the constructor which has the shortest parameter list.
  • ByPass - Doesn't change the constructor order, it'll use the first usable constructor.
  • WithDependencySelectionRule(...) - Sets the dependency selection rule.
  • PreferLastRegistered - Prefers the last registered service.
  • PreferFirstRegistered - Prefers the first registered service.
  • ByPass - Doesn't change the dependency order, it'll use the first usable dependency.
  • WithEnumerableOrderRule(...) - Sets the enumerable ordering rule.
  • PreserveOrder - Preserves the registration order of the resolved services.
  • ByPass - Doesn't change the resolution order of the services.