question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] Parameterized dependencies

See original GitHub issue

First check

  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.

Description

How can I create an async Parameterized dependency?

I found this link but I’m not quite sure it is the best option to my use case.

I have an authentication dependency with the following signature:

async def verify_token(request: Request):

And I needed to pass a boolean as a parameter, like:

async def verify_token(request: Request, get_details: boolean = False):

So I though that the best way would be to create a class to do it, but I’m not quite sure about it.

Any thoughts about this? Thanks in advance!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
victoraugustollscommented, Feb 27, 2020

Solved the issue on my end, thanks for the help!

0reactions
tiangolocommented, Apr 6, 2020

Thanks for reporting back and closing the issue 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Dependencies - FastAPI
Let's imagine that we want to have a dependency that checks if the query parameter q contains some fixed content. But we want...
Read more >
Dependency injection using parameters | F# for fun and profit
In this series, we are looking at six different approaches to dependency injection. In the first post, we looked at “dependency retention” ...
Read more >
How to achieve nested parameterized dependencies? #1655
The issue here is simply that currently parameterized dependencies do not work as sub dependencies. This really limits their usability. For us ...
Read more >
Use just one parameter for all dependencies instead of many?
The point is a service locator is an object that has the dependencies of other objects. The better question is, if you are...
Read more >
Combining DI with constructor parameters? - Stack Overflow
Our approach is to create a factory via D.I., and the factory's Create method would then build itself out using the passed in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found