-
Notifications
You must be signed in to change notification settings - Fork 10
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.
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 toThrowException
.
When any of above occurs the container throws a specific exception.
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 value0
which indicates that the related service is state-less, so it could be injected into any service.
These are the currentLifeSpan
values:- Singleton: 20
- Scoped: 10
- NamedScope: 10
- PerScopedRequest: 0
- Transient: 0
- Service registration
- Factory registration
- Assembly registration
- Composition
- Fluent registration api
- Service resolution
- Resolution by attributes
- Conventional resolution
- Delegate resolution
- Conditional resolution
- Multi resolution
- Lifetimes
- Generics
- Generic wrappers
- Decorators
- Resolvers
- Scopes
- Container configuration
- Container diagnostics
- Exceptions