Skip to content

Migration guide from dependency_injector #60

Closed

Description

@JobaDiniz
  1. It's written that this lib does not have wiring. What's the alternative and why it does not matter? What do I need to change?
  2. I'm using dead dependency_injector for fastapi. Does that-depends support passing the request: Request into the dependency?

https://that-depends.readthedocs.io/introduction/fastapi.html

@app.get("/")
async def read_root(
    some_dependency: typing.Annotated[
        container.DependentFactory,
        fastapi.Depends(container.DIContainer.dependent_factory),
    ],
) -> datetime.datetime:
    return some_dependency.async_resource

In the above example, I need that the instance of dependent_factory to have access to the request object of fastapi. How can this be implemented?

Activity

  1. lesnik512 commented on Aug 8, 2024

    @lesnik512
    Member

    @JobaDiniz Hi,

    1. The alternative is that there is no container initialization and you can't have several instances of the same container.
      the main advantage is that you don't need to write such boilerplate code:
        container = Container()
        container.wire(modules=[__name__])
  2. lesnik512 commented on Aug 8, 2024

    @lesnik512
    Member

    @JobaDiniz
    2. can you please show how you solve this case in dependency injector?

  3. JobaDiniz commented on Aug 9, 2024

    @JobaDiniz
    Author

    I haven't solved.

  4. lesnik512 commented on Aug 9, 2024

    @lesnik512
    Member
    1. there is only one clean solution I can think off:
    @app.get("/")
    async def read_root(request: Request) -> datetime.datetime:
        # and here build dependency and pass data from request to needed methods
        some_object = await container.DIContainer.dependent_factory()
        some_object.some_method(request)
  5. locked and limited conversation to collaborators on Aug 11, 2024
  6. converted this issue into a discussion #65 on Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions