Interfaces (Protocol/ABC)¶
If your code depends on abstractions (Protocols/ABCs), you must tell diwire what concrete class to build.
Use add(..., provides=...):
from typing import Protocol
from diwire import Container, Lifetime
class Clock(Protocol):
def now(self) -> str: ...
class SystemClock:
def now(self) -> str:
return "now"
container = Container()
container.add(SystemClock, provides=Clock,
lifetime=Lifetime.SCOPED,
)
Example (runnable)¶
See Registration methods.