-
Notifications
You must be signed in to change notification settings - Fork 2
Dependency checking
The Spring.FluentContext allows to configure object dependencies using explicit way or autowiring, however none of it guarantees that object is fully configured. Dependency checking feature allows to verify if all dependencies were injected to object during its configuration.
The CheckDependencies() method offers this functionality. It accepts Spring.Objects.Factory.Support.DependencyCheckingMode
enum parameter, which can have following values:
-
None
- no dependency checking, -
Simple
- dependency checking for primitive and collection types only, -
Object
- dependency checking for dependent objects, -
All
- dependency checking for all types (primitives, objects and collections).
There is also parameterless overload of CheckDependencies() method which uses All
mode.
The following example shows usage of CheckDependencies() method:
ctx.RegisterDefault<Cat>()
.BindConstructorArg<string>().ToValue("Kitty")
.CheckDependencies();
ctx.RegisterDefault<PersonWithCat>()
.UseConstructor((string name, Cat cat) => new PersonWithCat(name, cat))
.BindConstructorArg().ToValue("Josephine")
.BindConstructorArg().ToRegisteredDefault()
.CheckDependencies();
Please note that by default dependency check is OFF
Please note that if object contains public properties which accepts null
value, they would be reported as unsatisfied dependency
For details, please see 5.3.7. Checking for dependencies
Continue reading: 13. Aliasing