We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
based on whats provided in the context i'd like to choose different implementation paths
FORCE_USERNAME = NewType("FORCE_USERNAME", str) UserDetails = NewType("UserDetails") Class UserProvider(Provider): forced_username = fromContext(FORCE_USERNAME) @provide def user_lookup(self) -> UserLookup: return UserLookup() @provide def user_forced(self, username: FORCE_USERNAME, lookup: UserProvider) -> UserDetails: return lookup[username] user_fromcontext = from_context(UserDetails) @provide def default_user(self, lookup: UserLookup) -> UserDetails: return lookup.default_user c = makeContainer(UserProvider()): with c(context={FORCE_USERNAME: "bad" ) as sub: sub.get(UserDetails) # look up the specific user with c(context={UserDetails: UserDetails(...)}) as sub: sub.get(UserDetails) # use the provided one with c() as sub: sub.get(UserDetails) # get the default one
The text was updated successfully, but these errors were encountered:
Relates to #9 but suggests selection based on context contents, not only values
Sorry, something went wrong.
No branches or pull requests
based on whats provided in the context i'd like to choose different implementation paths
The text was updated successfully, but these errors were encountered: