Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Auto link the dependencies based on the type annotations #535

iorlas started this conversation in Ideas
Discussion options

Right now, it is required to define each dependency manually:

class Container(containers.DeclarativeContainer):
 database = providers.Singleton(sqlite3.connect, ":memory:")
 user_service = providers.Factory(
 UserService,
 db=database,
 )
 auth_service = providers.Factory(
 AuthService,
 db=database,
 user_service=user_service,
 )

It would be much easier and helpful, if it could automatically guess the types of the data and build the dependency tree based on it:

class Container(containers.DeclarativeContainer):
 database = providers.Singleton(sqlite3.connect, ":memory:")
 user_service = providers.Factory(UserService)
 auth_service = providers.Factory(AuthService)
class UserService:
 def __init__(self, db: sqlite3.Connection):
 self.db = db
class AuthService:
 def __init__(self, db: sqlite3.Connection, user_service: UserService):
 self.db = db
 self.user_service = user_service

What do you think?

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /