22to register services.
33"""
44
5- from collections .abc import Callable
6- from typing import Literal , TypeVar
7-
85from .service_provider import Service , ServiceProvider
9-
10- T = TypeVar ('T' )
6+ from .types import Implementation , Lifetime , T
117
128
139class ServiceCollection :
@@ -49,7 +45,7 @@ def __init__(self) -> None:
4945 def add_singleton (
5046 self ,
5147 service_type : type [T ],
52- implementation : type [ T ] | Callable [..., T ] | None = None ,
48+ implementation : Implementation = None ,
5349 ):
5450 """Register a service as a singleton
5551 (one instance for the application lifetime).
@@ -61,7 +57,7 @@ def add_singleton(
6157 ----------
6258 service_type : type[T]
6359 Service type.
64- implementation : type[T] | Callable[..., T] | None , optional
60+ implementation : Implementation , optional
6561 Implementation type or factory function, by default None.
6662
6763 Returns
@@ -86,7 +82,7 @@ def add_singleton(
8682 def add_transient (
8783 self ,
8884 service_type : type [T ],
89- implementation : type [ T ] | Callable [..., T ] | None = None ,
85+ implementation : Implementation = None ,
9086 ):
9187 """Register a service as transient
9288 (new instance created each time it's requested).
@@ -98,7 +94,7 @@ def add_transient(
9894 ----------
9995 service_type : type[T]
10096 Service type.
101- implementation : type[T] | Callable[..., T] | None , optional
97+ implementation : Implementation , optional
10298 Implementation type or factory function, by default None.
10399
104100 Returns
@@ -123,7 +119,7 @@ def add_transient(
123119 def add_scoped (
124120 self ,
125121 service_type : type [T ],
126- implementation : type [ T ] | Callable [..., T ] | None = None ,
122+ implementation : Implementation = None ,
127123 ):
128124 """Register a service as scoped
129125 (one instance per request).
@@ -135,7 +131,7 @@ def add_scoped(
135131 ----------
136132 service_type : type[T]
137133 Service type.
138- implementation : type[T] | Callable[..., T] | None , optional
134+ implementation : Implementation , optional
139135 Implementation type or factory function, by default None.
140136
141137 Returns
@@ -159,9 +155,9 @@ def add_scoped(
159155
160156 def add (
161157 self ,
162- lifetime : Literal [ 'singleton' , 'scoped' , 'transient' ] ,
158+ lifetime : Lifetime ,
163159 service_type : type [T ],
164- implementation : type [ T ] | Callable [..., T ] | None = None ,
160+ implementation : Implementation = None ,
165161 ):
166162 """Registers a service.
167163
@@ -174,7 +170,7 @@ def add(
174170 Lifetime of the service.
175171 service_type : type[T]
176172 Service type.
177- implementation : type[T] | Callable[..., T] | None , optional
173+ implementation : Implementation , optional
178174 Implementation type or factory function, by default None.
179175
180176 Returns
0 commit comments