registry

class litestar.stores.registry.StoreRegistry[源代码]

基类:object

Registry for Store instances.

__init__(stores: dict[str, Store] | None = None, default_factory: Callable[[str], Store] = <function default_default_factory>) None[源代码]

Initialize StoreRegistry.

参数:
  • stores -- A dictionary mapping store names to stores, used to initialize the registry

  • default_factory -- A callable used by StoreRegistry.get() to provide a store, if the requested name hasn't been registered yet. This callable receives the requested name and should return a Store instance.

register(name: str, store: Store, allow_override: bool = False) None[源代码]

Register a new Store.

参数:
  • name -- Name to register the store under

  • store -- The store to register

  • allow_override -- Whether to allow overriding an existing store of the same name

抛出:

ValueError -- If a store is already registered under this name and override is not True

get(name: str) Store[源代码]

Get a store registered under name. If no such store is registered, create a store using the default factory with name and register the returned store under name.

参数:

name -- Name of the store

返回:

A Store