Replies: 4 comments 3 replies
-
I'm not that clear in the question. Might help to add some code to illustrate what you're asking? |
Beta Was this translation helpful? Give feedback.
-
If I understand correctly, you're looking for a way to express that your One option is to guard the import in
This can be cumbersome if you have a lot of models or functions, but it's probably the safest way to express that you want "something that has an |
Beta Was this translation helpful? Give feedback.
-
Did you find a solution? I have a similar problem and I do not like the domain to depend on the model from the routes (BaseModel) |
Beta Was this translation helpful? Give feedback.
-
How to convert between inner and outer models without too much boilerplate
or code that needs to be maintained is still unclear for me, like the
builder/factory you mentioned.. Thanks anyway!
Alex Lopez ***@***.***> schrieb am Do., 12. Dez. 2024, 16:24:
… I didn't but the models from the routes may be different from the ones
from the domain. Even you may have different similar models in the routes
(User with password or without, or partially filled). There are some
examples in FastAPI docs about this.
In addition, a change in the API will force a change in the domain if you
reuse the same model. So I would avoid as much as possible to have that
dependency.
You can have something like a builder/factory between route and domain
models but I would like to find examples of someone else doing it...
I'm not currently building anything similar so I will have to take a look
at what others are recommending.
—
Reply to this email directly, view it on GitHub
<#4729 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJCRNQMK6ZCITINIBAICE732FGTEVAVCNFSM6AAAAABSAFFLXGVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTCNJUGU4TIMI>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
👋 hey!
I love using pydantic with fastapi. I am trying to build clean architecture using domain driven design.
In reality my main goal is not to allow 3rd partly libs to be direct dependencies of the inner layers of my system.
Since we are defining types using pydantic right at the outer layer it than feels like a good idea to just import this type across all the other layers when needed.
Is there a way to avoid this? Using sometime like dependency inversion or create some more generic interface?
Thanks!!!
EDIT - asked for an example in the comments.
So this file is all good! We have our later layer of the system and it depends on pydantic BaseModel.
Now we write the code for our use case (inner business logic).
Hopefully that helps?
The issue is that the inner business logic layers should not depend directly on
BaseModel
as this could be replaced in future.Beta Was this translation helpful? Give feedback.
All reactions