-
-
Notifications
You must be signed in to change notification settings - Fork 133
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Checklist
- I believe the idea is awesome and would benefit the framework
- I have searched in the issue tracker for similar requests, including closed ones
Description
Dependency injection is a powerful and convenient design pattern — and with FunDI, integrating it becomes effortless.
Since this library supports Python up to 3.9, the best way to include it as an optional dependency is like so:
pip install pyrofork[fundi]
Proposed Integration Example
from fundi import from_, FromType
from pyrogram import Client, filters
from pyrogram.types import Message
app = Client("my_account")
def require_user_mention(message: FromType[Message]) -> str:
user = message.from_user
if user.username is not None:
return f"{user.mention}(@{user.username}|{user.id})"
return f"{user.mention}({user.id})"
@app.on_message(filters.private)
async def hello(
message: FromType[Message],
mention: str = from_(require_user_mention),
):
await message.reply(f"Hello, {mention}!")🛠 How It Works
- The
mentionargument is automatically injected viafrom_(), which tells FunDI to resolve it usingrequire_user_mention. FromType[Message]is a type hint that marks themessageas an injectable Pyrogram context.require_user_mentionis a plain function (sync or async) that acceptsMessageand returns a formatted string.
This approach keeps your handlers clean, modular, and readable.
FunDI handles the wiring — you just write logic.
BenjiThatFoxGuy
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request