Consider using a decorator to facilitate adapter class self registration. This approach streamlines the registration process a little without the need to manually update the factory. e.g., in AuthFactory:
_registry: typing.ClassVar[dict[str, BaseAuthAdapter]] = {}
@classmethod
def register(cls, name: str) -> Callable:
def decorator(subclass: BaseAuthAdapter) -> BaseAuthAdapter:
cls._registry[name] = subclass
return subclass
return decorator
Then adapter classes can register themselves like:
@Authfactory.register("fastapi")
class FastAPIAuthAdapter(BaseAuthAdapter):
...
dataone-auth/src/dataone/auth.py
Line 326 in 44a01d4
Consider using a decorator to facilitate adapter class self registration. This approach streamlines the registration process a little without the need to manually update the factory. e.g., in
AuthFactory:Then adapter classes can register themselves like: