Interfaces (Protocol/ABC)

If your code depends on abstractions (Protocols/ABCs), you must tell diwire what concrete class to build.

Two common ways:

  1. concrete_class=...:

    container.register(Clock, concrete_class=SystemClock)
    
  2. Decorator:

    @container.register(Clock, lifetime=Lifetime.SINGLETON)
    class SystemClock:
        ...
    

Example (runnable)

See the runnable script in Patterns (Interface registration section).