Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
maldoinc committed Dec 29, 2023
1 parent 89277d0 commit 1f8a57c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
10 changes: 5 additions & 5 deletions docs/pages/service_override.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ which will help temporarily overriding dependencies


!!! info "Good to know"
* Overriding only applies to subsequent autowire calls.
* If a singleton service has been initialized, it is not possible to override any
of its dependencies as the object is already in memory. You may need to override
the first service directly instead of any transient dependencies.
* When using interfaces override the interface rather than any impl.
* Overriding only applies to future autowire calls.
* If a singleton service A has been initialized, it is not possible to override any
of its dependencies as the object is already in memory. You may need to override
Service A directly instead of any transient dependencies.
* When using interfaces override the interface rather than any of its implementations.

## Example

Expand Down
7 changes: 2 additions & 5 deletions wireup/ioc/override_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def clear(self) -> None:

@contextmanager
def service(self, target: type, new: Any, qualifier: ContainerProxyQualifierValue = None) -> Iterator[None]:
"""Override the target service with new for the duration of the context manager.
"""Override the `target` service with `new` for the duration of the context manager.
Subsequent autowire calls to `target` will result in `new` being injected.
Expand All @@ -53,10 +53,7 @@ def service(self, target: type, new: Any, qualifier: ContainerProxyQualifierValu

@contextmanager
def services(self, overrides: list[ServiceOverride]) -> Iterator[None]:
"""Override the target service with new for the duration of the context manager.
Behavior is identical to `override`, except this supports overriding multiple services at a time.
"""
"""Override a number of services with new for the duration of the context manager."""
try:
for override in overrides:
self.set(override.target, override.new, override.qualifier)
Expand Down

0 comments on commit 1f8a57c

Please sign in to comment.