Replies: 2 comments 1 reply
-
Hi @felippemr, thank you for sharing this! Currently, # mymodule.py
@inject
async def create_item(session: AsyncSession = Provide[Container.session]):
... Thus, I specify explicitly the provider that then injects the dependency. # container.py
class Container(BaseContainer):
config = providers.Singleton(Config)
session = providers.ContextResource(create_async_session, config=config) And finally, the functions/classes that actually generate the dependencies: # deps.py
from pydantic_settings import BaseSettings
class Config(BaseSettings):
host: str
port: str
async def create_async_session(config: Config):
# creates an async sqlalchemy session
.... You can also see a pretty good example for this in the fastapi template. Thus, in my average case, getting to the implementation is just 2 "go to implementation" (for example Ctrl + B in Pycharm) away (without having multiple options to select from). Now In general, in the current state of the project, I am not sure if a tool like you suggests would be too useful, but I can see it being more relevant as the project grows. Currently, the resolution framework of This is my personal opinion, it is likely someone else has a different one. |
Beta Was this translation helpful? Give feedback.
-
I agree with @alexanderlazarev0 |
Beta Was this translation helpful? Give feedback.
-
Hi folks I created a small POC of an LSP that parses container.py files and is able to serve "Go to implementation" requests.
Let me know your thoughts as this is something I could invest more time on if folks see some value. I did it using another DI lib but I could improve it so that it works with multiple providers. Is this something you would be interested in?
https://renard-engineering.ghost.io/guerrilla-coding-enabling-subcultures-to-thrive-through-custom-made-tooling/
Beta Was this translation helpful? Give feedback.
All reactions