reagento / dishka

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

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

Closed KOT4N closed 1 month ago

KOT4N commented 1 month 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 1 month 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 1 month ago

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