You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use case: Interactor depends on StatisticDbGateway and MainDbGateway. Each of them uses SQLAlchemy Session object, so they have similar init typehints. The difference is that StatisticDbGateway requires Session bound to ClickhouseEngine, while MainDbGateway binds to postgresqlEngine. Again both engines have same type, but created differently.
To solve this you can replace Session with some new type (literally NewType("PgSession", Session)), but it requires modification of all code base. Imagine that you took those objects from external library and cannot modify it.
Another solution is again to use NewType, but create factories for all objects instead of registrering classes as depedencies directly. This requries a lot of work.
Proposed solution is to split those objects in 3 groups:
Each graph here uses only his factories to solve dependencies or requests specially attached subgraphs. So here, gateways can request Session and they get exactly that session which is declared in his subgraph.
Requirements:
(Sub)graphs can have subgraphs
All (Sub)graphs are synchronized by scopes
Subgraph cannot access depedencies from parent graph
When looking for factories subgraphs are requested only if they are not found in current graph itself.
It is an open question whether (sub)graph is just a container or another thing
The text was updated successfully, but these errors were encountered:
On container creation you need somehow attatch providers to component names. It can be either provider attribute, or separate object or just a dictionary. E.g.
Use case:
Interactor
depends onStatisticDbGateway
andMainDbGateway
. Each of them uses SQLAlchemySession
object, so they have similar init typehints. The difference is thatStatisticDbGateway
requiresSession
bound to ClickhouseEngine
, whileMainDbGateway
binds to postgresqlEngine
. Again both engines have same type, but created differently.To solve this you can replace
Session
with some new type (literallyNewType("PgSession", Session)
), but it requires modification of all code base. Imagine that you took those objects from external library and cannot modify it.Another solution is again to use
NewType
, but create factories for all objects instead of registrering classes as depedencies directly. This requries a lot of work.Proposed solution is to split those objects in 3 groups:
SubGraph1:
StatisticDbGateway
,Session
,Engine
SubGraph2:
MainDbGateway
,Session
,Engine
MainGraph:
Interactor
,SubGraph1
,SubGraph2
Each graph here uses only his factories to solve dependencies or requests specially attached subgraphs. So here, gateways can request Session and they get exactly that session which is declared in his subgraph.
Requirements:
It is an open question whether (sub)graph is just a container or another thing
The text was updated successfully, but these errors were encountered: