-
-
Notifications
You must be signed in to change notification settings - Fork 331
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
base: develop
Are you sure you want to change the base?
Conversation
…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
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
.
def init_resources(self, resource_type: Type[Resource]=None) -> Optional[Awaitable]: ... | ||
def shutdown_resources(self, resource_type: Type[Resource]=None) -> Optional[Awaitable]: ... |
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.
def init_resources(self, resource_type: Type[Resource]=None) -> Optional[Awaitable]: ... | |
def shutdown_resources(self, resource_type: Type[Resource]=None) -> Optional[Awaitable]: ... | |
def init_resources(self, resource_type: Type[Resource[Any]] = Resource) -> Optional[Awaitable[None]]: ... | |
def shutdown_resources(self, resource_type: Type[Resource[Any]] = Resource) -> Optional[Awaitable[None]]: ... |
@@ -333,11 +333,11 @@ class DynamicContainer(Container): | |||
self.wired_to_modules.clear() | |||
self.wired_to_packages.clear() | |||
|
|||
def init_resources(self): | |||
def init_resources(self, resource_type=providers.Resource): |
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.
We need issubclass
check for resource_type
arg.
@@ -346,7 +346,7 @@ class DynamicContainer(Container): | |||
if futures: | |||
return asyncio.gather(*futures) | |||
|
|||
def shutdown_resources(self): | |||
def shutdown_resources(self, resource_type=providers.Resource): |
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.
We need issubclass
check for resource_type
arg.
Yep! Exactly, it's a workaround. When I started with this, my first approach was to refact the current |
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