From 28f2f207ff7ccf89761652251a74e04cd6e03fa2 Mon Sep 17 00:00:00 2001 From: Aldo Mateli Date: Sun, 10 Sep 2023 00:44:12 +0100 Subject: [PATCH] Docs update --- docs/pages/factory_functions.md | 14 ++++++++++++++ docs/pages/index.md | 3 +-- docs/pages/manual_configuration.md | 11 +++++++++++ docs/pages/quickstart.md | 6 +++--- docs/pages/stylesheets/extra.css | 5 ++++- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/pages/factory_functions.md b/docs/pages/factory_functions.md index d6f008f..34fd633 100644 --- a/docs/pages/factory_functions.md +++ b/docs/pages/factory_functions.md @@ -58,6 +58,20 @@ def get_user_logs(user: AuthenticatedUser): ... ``` +Assume a base class `Notifier` with implementations that define how the notification is sent (IMAP, POP, WebHooks, etc.) +Given a user it is possible to instantiate the correct type of notifier based on user preferences. + + +```python +@container.register +def get_user_notifier(user: AuthenticatedUser) -> Notifier: + notifier_type = ... + + return container.get(notifier_type) +``` + +When injecting `Notifier` the correct type will be created based on the authenticated user's preferences. + ## Links * [Introduce to an existing project](introduce_to_an_existing_project.md) diff --git a/docs/pages/index.md b/docs/pages/index.md index 2dd1894..1c9791a 100644 --- a/docs/pages/index.md +++ b/docs/pages/index.md @@ -1,8 +1,7 @@ # :thread: WireUp Dependency injection library designed to provide a powerful and flexible way to -manage and inject dependencies across your application, -making it easier to develop, test, and maintain Python codebases. +manage and inject dependencies making it easier to develop, test, and maintain Python codebases. ## Key features diff --git a/docs/pages/manual_configuration.md b/docs/pages/manual_configuration.md index ff4ae50..9aaab7e 100644 --- a/docs/pages/manual_configuration.md +++ b/docs/pages/manual_configuration.md @@ -15,6 +15,17 @@ on each. container.register_all_in_module(app.service, "*Service") ``` +## Interfaces + +Even though It's not possible to automatically register abstract types and implementation using qualifiers. +Manual registration is still possible. + +```python +container.abstract(FooBase) +container.register(FooBar, qualifier="bar") +container.register(FooBaz, qualifier="baz") +``` + ## Manually wiring parameters Given that parameters can't be resolved from type annotations alone, the `container.wire` method offers two shortcuts diff --git a/docs/pages/quickstart.md b/docs/pages/quickstart.md index b5f6693..7315b10 100644 --- a/docs/pages/quickstart.md +++ b/docs/pages/quickstart.md @@ -35,7 +35,7 @@ class DbService: @container.register @dataclass class UserRepository: - db: DbService # Dependencies may also depend on other dependencies. (2)! + db: DbService# Dependencies may also depend on other dependencies. (2)! ``` 1. The decorators do not modify the classes in any way and only serve to collect metadata. This behavior can make @@ -45,9 +45,8 @@ class UserRepository: **3. Inject** ```python -# Decorate all methods where the library must perform injection. @app.route("/greet/") -@container.autowire +@container.autowire#(2)! # Classes are automatically injected based on annotated type. # Parameters will be located based on the hint given in their default value. # Unknown arguments will not be processed. @@ -57,6 +56,7 @@ def greet(name: str, user_repository: UserRepository, env: str = wire(param="env 1. We know that this will be used in conjunction with many other libraries, so WireUp will not throw on unknown parameters in order to let other decorators to do their job. +2. Decorate all methods where the library must perform injection. **Installation** diff --git a/docs/pages/stylesheets/extra.css b/docs/pages/stylesheets/extra.css index 3692019..339d5ca 100644 --- a/docs/pages/stylesheets/extra.css +++ b/docs/pages/stylesheets/extra.css @@ -23,12 +23,15 @@ dd, dd p { .card { flex: 0 1 calc(50% - 5px); - background-color: #ffffff; border: 1px solid #ddd; border-radius: 3px; padding: 20px; } +body[data-md-color-scheme="slate"] .card { + border: 1px solid var(--md-default-fg-color--lightest) !important; +} + .card-title{ font-weight: bold; display: flex;