-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
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
feat: naive Factory implementation for getting rid of lambdas #163
Conversation
@ShahriyarR this idea looks very interesting and indeed what we have discussed. Do you think you are able to also update the docs for this with examples and how tos? |
@tarsil yes, I will add docs as well. I also need to add more tests for checking Route Level DI or Handler Level, I am still not sure how we call it :) |
So, we have dependencies from the Esmerald instance down to handler (get, post, put....). So that means, Esmerald, Include, Gateway/WebSocketGateway and the handlers in general 🙂 You can see that also in the Esmerald tests 👍🏼 |
d66a7e7
to
f9cbf59
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The examples are actually really great and simple to understand. Apologies for the comments in the documentation but it is more to be consistent with the way we try to provide the "guide" through those same docs. As mentioned before, it is more like a story telling but with structure :)
class Factory: | ||
def __init__(self, provides: "AnyCallable", *args: Any) -> None: | ||
self.provides = provides | ||
self.__args: Tuple[Any, ...] = () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be:
self.__args: Tuple[Any, ...] = args
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done directly, but personally I prefer to use the getter and setter way of dealing with internal objects:
self.__args: Tuple[Any, ...] = ()
self.set_args(*args)
Looks good to me 👍🏼 . Good stuff @ShahriyarR . We can grow this functionality even further |
Description:
When I was trying to add DAOs as a dependency, Inject requires the lambda or partial as described here:
Implemented naive, but yet clean wrapper called Factory to inject as:
For now, it only supports variable arguments(*args)
Mostly inspired by:
https://python-dependency-injector.ets-labs.org/providers/factory.html
Information:
In the future possible TODOs:
**kwargs
supportobj = Factory(UserDAO); obj.add_args(*args)