-
Notifications
You must be signed in to change notification settings - Fork 10
Container diagnostics
Peter Csajtai edited this page Oct 19, 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 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 the 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.
- Unresolvable type: when a requested type is not instantiable (e.g. it doesn't have a public constructor) the container throws an exception with every diagnostic detail included.
- Missing dependency: when a type the requested service is depending on is not resolvable (either as a constructor parameter or a class member), the container throws an exception with every diagnostic detail 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 than 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
- Circular dependency: when the container notices an infinite dependency loop in the resolution graph, it throws an exception with every diagnostic detail included.
You can check the containers state anytime by calling its .Validate()
function, it walks through the whole dependency tree and collects all the issues into an AggreagteException
.
- 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