Closed lesnik512 closed 4 months ago
import dataclasses import pydantic from that_depends import BaseContainer, providers @dataclasses.dataclass(kw_only=True, slots=True) class SingletonFactory: dep1: str class Settings(pydantic.BaseModel): some_setting: str = "some_value" other_setting: str = "other_value" class DIContainer(BaseContainer): settings: Settings = providers.Singleton(Settings).cast singleton = providers.Singleton(SingletonFactory, dep1=settings.some_setting) async def test_singleton_attr_getter() -> None: singleton1 = await DIContainer.singleton() assert singleton1.dep1 == Settings().some_setting await DIContainer.tear_down()
@jasonprado @vrslev hello, guys! What do you think about this way of lazy attributes getting?
Hey there!
I guess, if mypy is happy then it works!
Yes, indeed: I like it 👍