-
-
Notifications
You must be signed in to change notification settings - Fork 332
Feature: Add resource type parameter to init and shutdown resources using specialized providers #858
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
Feature: Add resource type parameter to init and shutdown resources using specialized providers #858
Conversation
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.
Pretty useful!
@ZipFile any changes to make this merge? |
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.
Hey! Sorry for delay. I have mixed feeling about this change, since this is not a proper scoping implementation, but rather a workaround. Either way, I think we can accept it for now, since introducing real scopes would probably require some serious re-engeneering on our part.
I've left some comments to the code + we need to add support for passing provider class in the Lifespan
from dependency_injector.ext.starlette
.
Yep! Exactly, it's a workaround. When I started with this, my first approach was to refact the current |
…sources` methods to provide a more granular way to initialize the desired resources and add the possibility to scope that ones.
…nd shutdown_resources using the resource_type argument and how can scope the resources
948a762
to
cde7eaf
Compare
cde7eaf
to
4604341
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.
Bug: Invalid Resource Type Causes Incorrect Error
The init_resources
and shutdown_resources
methods raise a generic TypeError
("issubclass() arg 1 must be a class") when the resource_type
parameter is a non-class value (e.g., None, string, number). This occurs because the issubclass()
check is performed directly on the input without first validating if resource_type
is a class, leading to inconsistent error messages compared to the intended custom TypeError
.
src/dependency_injector/containers.pyx#L320-L322
python-dependency-injector/src/dependency_injector/containers.pyx
Lines 320 to 322 in 4604341
if not issubclass(resource_type, providers.Resource): | |
raise TypeError("resource_type must be a subclass of Resource provider") |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Objective
Enable the initialization and shutdown of resources by specifying their type. This allows you to create logical groups of resources and handle them by type, similar to applying resource scoping.
Changes