Skip to content
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

Pydantic and Kink #56

Closed
YanSte opened this issue May 16, 2024 · 2 comments
Closed

Pydantic and Kink #56

YanSte opened this issue May 16, 2024 · 2 comments

Comments

@YanSte
Copy link

YanSte commented May 16, 2024

Hi,

Thank you very much for your work on this library. It's simple and easy to use. I considered using another library, but it hasn't been updated.

I have a question regarding the integration with Pydantic. Specifically, I want to know how to use dependency injection with Pydantic models. Here's what I mean:

@inject
class A(BaseModel):
    ...
    b: B

Is it possible to inject B without implementing the __init__ method manually?

Thank you!

@YanSte
Copy link
Author

YanSte commented May 16, 2024

I found this solution: (Pydantic v1)

# No @inject
class A(BaseModel):
    ...
    b: B = Field(default_factory=lambda: di[B])

Could you tell me what you think?

@YanSte
Copy link
Author

YanSte commented May 16, 2024

After a try that works great ✌️ Thanks a lot you save my time.

@YanSte YanSte closed this as completed May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant