Registry
Base class for all registries in the BFM framework.
Generic Registry with lazy autodiscovery.
Example usage:
from bfm.core.registry import Registry
items = Registry() # create a registry for the current package
@items.register("my_item")
class MyItem:
def __init__(self, number: int):
...
my_item = items.resolve("my_item", number=4)
Registry
Bases: Generic[T]
Create a registry for all items in a package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package
|
Optional[str]
|
Dotted path of the package to scan for items (modules under it should import and call @register). If no package is specified, the caller's package will be used. |
None
|
relative
|
bool
|
If True, the package is treated as relative to the caller's package. |
True
|
Source code in bfm/core/registry.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
contains(name)
Return True if the registry contains the given name.
Source code in bfm/core/registry.py
122 123 124 125 126 | |
get(name)
Get a factory by name.
Source code in bfm/core/registry.py
104 105 106 107 108 109 110 111 112 113 114 | |
list()
Canonical keys (not aliases).
Source code in bfm/core/registry.py
128 129 130 131 | |
list_aliases()
alias → canonical mapping.
Source code in bfm/core/registry.py
133 134 135 136 | |
register(name, *aliases)
Register item under a canonical name and optional aliases.
Source code in bfm/core/registry.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
resolve(name, **kwargs)
Instantiate by name with kwargs.
Source code in bfm/core/registry.py
117 118 119 120 | |