reagento / dishka

Cute DI framework with agreeable API and everything you need
https://dishka.readthedocs.io
Apache License 2.0
430 stars 48 forks source link

Provider with component can't find factory for param #244

Closed KOT4N closed 2 months ago

KOT4N commented 2 months ago

Providers:

class DependProvider(Provider):
    @provide(scope=Scope.APP)
    def main_config(self) -> int:
        return 1

class SomethingProvider(Provider):
    component = "sth"

    @provide(scope=Scope.APP)
    def idk(self, param: int) -> any:
        return param

Container:

def make_container():
    container = make_async_container(
        DependProvider(),
        SomethingProvider()
    )
    return container

If it setups WITH component in SomethingProvider it raises

dishka.exceptions.GraphMissingFactoryError: Cannot find factory for (<class 'int'>, component='sth'). It is missing or has invalid scope.
      ~~~ component='sth', Scope.APP ~~~
   ↓  <built-in function any> SomethingProvider.idk
    → <class 'int'>           ???

WITHOUT component it works fine.

Tishka17 commented 2 months ago

That is expected behavior. This is how component isolation works.

To request object from another component you should use FromComponent according to the documentation

Tishka17 commented 2 months ago

The idea is to suggest corrections if we have corresponding type another component or scope