Skip to content

AliasSourceNotRegisteredError

Symptom

Raised naming the source_type an Alias points at, saying no provider is registered for it.

Cause

Alias(X) was declared, but no provider's bound_type resolves to X — either the provider for X was never defined, its group wasn't passed to Container(groups=[...]), or it was declared with bound_type=None (making it unresolvable by type, which an alias also can't reach). This is checked eagerly during validate(), and again at resolve time if validation was skipped.

Fix

Register (and include) a provider for the source type before defining the alias:

from modern_di import Group, Scope, providers


class Dependencies(Group):
    # The alias's source must resolve by type — no bound_type=None here.
    impl = providers.Factory(Implementation, scope=Scope.APP)

    interface_alias = providers.Alias(Implementation)

If the source provider lives in a different Group, make sure that group is also passed to Container(groups=[...]). Run with validate=True so this is caught at startup rather than on first resolve.

See also