Skip to content

suggestion for adapter registration #16

Description

@datadavev

_registry = {

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):
  ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

  • Status
    Ready

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions