Skip to content

Container diagnostics

Peter Csajtai edited this page Jun 26, 2020 · 9 revisions

Stashbox has some validation routines that helps you detect and solve common configuration issues.

Registration validation

The container executes validation against the given types of a registration.
The validation fails when:

  • The implementation type is not resolvable (it's an interface or an abstract class).
  • The implementation type does not implement the service type.
  • The given implementation type is already registered and the RegistrationBehavior container configuration option is set to ThrowException.

When any of above occurs the container throws a specific exception.

Dependency tree validation

During the construction of the dependency tree the container constantly checks its actual state to ensure its stability.

  • Missing dependency: when a type a service is depending on is not resolvable (either as a constructor parameter or a class member), the container throws an exception with every diagnostic details included, like which constructors were tried for resolution and which parameters were unable to resolve.
  • Lifetime validation: this validation enforces two rules and when they are violated, the container throws an exception.
    • When a scoped service is requested from the root scope.
    • When the life-span of a dependency is shorter then its parent's. Every lifetime has a LifeSpan value which determines how long the related service lives. The main rule is that services may not contain dependencies with shorter life-spans, like singletons should not depend on scoped services. The only exception is the life-span value 0 which indicates that the related service is state-less, so it could be injected into any service.
      These are the current LifeSpan values:
      • Singleton: 20
      • Scoped: 10
      • NamedScope: 10
      • PerScopedRequest: 0
      • Transient: 0