Auto-registration tuning¶
Auto-registration enables the “just write types, then resolve the root” experience.
Strict mode (disable auto-registration)¶
Disable auto-registration when you want your app to fail fast if anything is missing:
from diwire import Container, DependencyRegistrationPolicy, MissingPolicy
container = Container(
missing_policy=MissingPolicy.ERROR,
dependency_registration_policy=DependencyRegistrationPolicy.IGNORE,
)
In strict mode, resolving an unregistered dependency raises
diwire.exceptions.DIWireDependencyNotRegisteredError.
Autoregister concrete types vs dependencies¶
missing_policycontrols resolve-time behavior for unknown concrete classes.dependency_registration_policycontrols container-level defaults for whether provider dependencies are automatically registered as concrete types at registration time.dependency_registration_policyis the call-level override onadd,add_factory,add_generator,add_context_manager, andresolver_context.inject.
Pydantic settings auto-registration¶
If pydantic-settings is installed, subclasses of BaseSettings are auto-registered as
root-scoped Lifetime.SCOPED values (singleton behavior) via a no-argument factory.
See Integrations and Pydantic settings.
Scope-safety¶
If a type has any scoped registration, resolving it outside the correct scope raises
diwire.exceptions.DIWireScopeMismatchError instead of silently creating an unscoped instance.
Runnable example: Scopes & cleanup.