You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the current implementation, the Registry have to be first instantiated somewhere and the instance have to be then imported whenever one wants to use the registry.
Disadvantages
It might not be always clear where should one define the Registry instances. If defined in wrong place, it can cause issues with circular imports or similar import errors.
Solution
It would be advantageous for the registry instances to act as singletons based on the provided names.
That would mean that every time a registry with the same name is instantiated, the firstly created instance is returned instead of creating a new empty registry. This will make the registries a bit more convenient to use and avoids any possible import errors.
# ---- foo.py ---- fromluxonis_ml.utilsimportRegistry# If defined for the first time, creates a global static `Registry` instance.REGISTRY=Registry("registry_name")
@REGISTRY.register_module()classFoo:
pass
# ---- bar.py ----# no need to import REGISTRY from foo.pyfromluxonis_ml.utilsimportRegistryRegistry("registry_name").get("Foo")
# >>> <class '__foo__.Foo'>
To Consider
Should the names be case sensitive or not?
The text was updated successfully, but these errors were encountered:
Singleton Registry Pattern
In the current implementation, the
Registry
have to be first instantiated somewhere and the instance have to be then imported whenever one wants to use the registry.Disadvantages
It might not be always clear where should one define the
Registry
instances. If defined in wrong place, it can cause issues with circular imports or similar import errors.Solution
It would be advantageous for the registry instances to act as singletons based on the provided names.
That would mean that every time a registry with the same name is instantiated, the firstly created instance is returned instead of creating a new empty registry. This will make the registries a bit more convenient to use and avoids any possible import errors.
Current Method
Proposed Method
To Consider
The text was updated successfully, but these errors were encountered: