meadsteve / lagom

📦 Autowiring dependency injection container for python 3
https://lagom-di.readthedocs.io/en/latest/
MIT License
286 stars 15 forks source link

Request level singletons can not resolve fastapi/starlette Request class #228

Closed alkimake closed 1 year ago

alkimake commented 1 year ago

When resolving request level singletons, Request class from starlette can not be resolved

As an example, editing the tests located at tests/integrations/fastapi_app/__init__.py as;

 from contextlib import contextmanager
 from typing import Iterator

-from fastapi import FastAPI
+from fastapi import FastAPI, Request

 from lagom import Container, dependency_definition
 from lagom.integrations.fast_api import FastApiIntegration

 class Inner:
-    def __init__(self, msg=None):
+    def __init__(self, request: Request, msg=None):
         self.msg = msg
+        self.request = request

The resolution gives the following error;

lagom.exceptions.UnresolvableType: Unable to construct dependency of type Inner The constructor probably has some unre
solvable dependencies

I will try to make a PR when i have time. But not promise :D

meadsteve commented 1 year ago

This will be available in version 2.3.0 which is currently being published/built: https://github.com/meadsteve/lagom/actions/runs/4344660974