Injection return provide object not actual dependency object
See original GitHub issuei have a class to be injected src/runner_rating/api/rating/controller.py
class Rating():
@inject
def __init__(
self,
repo: RatingRepository = Provide[Container.repo.rating]):
self.repo = repo
def get_by_id(self, id):
data = self.repo.get_by_id(id)
if not data:
raise HTTPNotFoundException(self.repo.index_name)
this is my container looks like: src/container.py
class ESContainer(containers.DeclarativeContainer):
config = providers.Configuration()
client = providers.Singleton(
elasticsearch_client.ElasticsearchClient,
config=config.elasticsearch
)
class RepositoryContainer(containers.DeclarativeContainer):
config = providers.Configuration()
db = providers.DependenciesContainer()
rating = providers.Singleton(
RatingRepository,
db=db.client
)
class Container(containers.DeclarativeContainer):
config = providers.Configuration()
es = providers.Container(
ESContainer,
config=config
)
repo = providers.Container(
RepositoryContainer,
config=config,
db=es
)
this is when Container were called: src/application.py
from src import runner_rating
def main():
# register dependency
di_container = Container()
di_container.config.from_dict(config.get_config())
di_container.wire(modules=[runner_rating])
when i try Rating.get_by_id it shows error that:
data = self.repo.get_by_id(id)
AttributeError: 'Provide' object has no attribute 'get_by_id'
Why? i’am using v2.5.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (7 by maintainers)
Top Results From Across the Web
'Provide' object has no attribute 'test' - Stack Overflow
When I am injecting the dependencies to the endpoints I always gets Provide object not actual class object due to this code always...
Read more >Wiring — Dependency Injector 4.41.0 documentation
Wiring¶. Wiring feature provides a way to inject container providers into the functions and methods. To use wiring you need: Place @inject decorator....
Read more >Provide/Inject Have Nothing to Do With Dependency Injection
The dependencies aren't created by the object itself. Instead they are injected into the object when the program is running. These dependencies are...
Read more >Dependency injection guidelines - .NET | Microsoft Learn
This article provides general guidelines and best practices for implementing dependency injection in .NET applications.
Read more >Understanding dependency injection - Endjin
Dependency injection is the principle that the objects which a class needs should be 'injected' into it, not created inside it.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@ijalalfrz , try to change
di_container.wire(modules=[runner_rating])
todi_container.wire(packages=[runner_rating])
.Yes, ‘get_by_id()’ works because you call it in the runtime.
Thank you. My pleasure to help.
Best, Roman