Skip to content

Added a section on Dependency Injection technology in documentation #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 13, 2023
Merged

Conversation

wakaree
Copy link
Contributor

@wakaree wakaree commented Aug 8, 2023

Description

I often noticed that developers ignored the existence of the concept of dependency injection, using global variables or singleton instead. Previously, this topic was not covered in the documentation, which I corrected.

Type of change

  • Documentation (typos, code examples or any documentation update)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label Aug 8, 2023
@github-actions
Copy link

github-actions bot commented Aug 8, 2023

✔️ Changelog found.

Thank you for adding a description of the changes

@@ -0,0 +1,56 @@
######
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#sections

Section headers (ref) are created by underlining (and optionally overlining) the section title with a punctuation character, at least as long as the text

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,56 @@
######
Dependency injection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so this is a clear dependency injection mechanism, but i don't know another name for this feature

Copy link
Contributor Author

@wakaree wakaree Aug 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so this is a clear dependency injection mechanism

The basic concept of dependency injection is clearly visible in the example of passing a router to the current handler (by "event_router" keyword) - the handler itself depends on it and has access to it.

But you really can pass anything through the handling context and do it both at application startup and at runtime. 🧐
Nevertheless, I saw other libraries that also name the concept of passing arguments to the function by parameter names / type hints like "depends".

but i don't know another name for this feature

Maybe "Handling context"?

self,
message: Message,
event_from_user: User
# as I said previously, filters also can accept keyword parameters like in handlers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"As I said previously" is not clear sentence for this place in due to example can be viewed without reading documentation and this comment is first in this file, you say nothing previously.

return False


@router.message(HelloFilter(name=None))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name is optional argument, you shouldn't pass any balue to it

@JrooTJunior JrooTJunior merged commit f87deea into aiogram:dev-3.x Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issue or PR for stable 3.x version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants