OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to shutdown resources using dependency_injector

  • Thread starter Thread starter Victor Egiazarian
  • Start date Start date
V

Victor Egiazarian

Guest
I'm using dependency_injector to manage DI. I don't understand how to release my resources using this library.

I found shutdown_resources method but have no idea how to use it properly.

Example:

Code:
class Resource:
    """Resource example."""

    def __init__(self):
        """."""

        # Initialize session

    def close(self):
        """Release resources."""

        # Close session

class ApplicationContainer(DeclarativeContainer):
    """Application container."""

    resource: Singleton[Resource] = Singleton[Resource](Resource)


container = ApplicationContainer()
# Do something
container.shutdown_resources() # Call close method here
<p>I'm using <a href="https://python-dependency-injector.ets-labs.org/index.html" rel="nofollow noreferrer">dependency_injector</a> to manage DI. I don't understand how to release my resources using this library.</p>
<p>I found <a href="https://python-dependency-injector.ets-labs.org/index.html" rel="nofollow noreferrer">shutdown_resources</a> method but have no idea how to use it properly.</p>
<p><strong>Example:</strong></p>
<pre class="lang-py prettyprint-override"><code>class Resource:
"""Resource example."""

def __init__(self):
"""."""

# Initialize session

def close(self):
"""Release resources."""

# Close session

class ApplicationContainer(DeclarativeContainer):
"""Application container."""

resource: Singleton[Resource] = Singleton[Resource](Resource)


container = ApplicationContainer()
# Do something
container.shutdown_resources() # Call close method here
</code></pre>
 
Top