core_lib.core_lib.CoreLib [source]
CoreLib
class is the front of the entire library. It exposes all the “Services” your library offers by using simple Services
, DataAccess
, and Clients
assignments to YourCoreLib class. You define your library interface.
Usage
from core_lib.core_lib import CoreLib
from core_lib.helpers.config_instances import instantiate_config
...
class YourCoreLib(CoreLib):
def __init__(self, config: DictConfig):
CoreLib.__init__(self)
self.email = instantiate_config(self.config, EmailCoreLib) # instantiate `EmailCoreLib` from config
user_da = UserDataAccess(instantiate_config(self.config.core_lib.data.db, SqlAlchemyConnectionRegistry))
self.user = UserService(user_da)
self.user_photos = UserPhotosService(user_da)
...
Code Explained:
YourCoreLib
class is extending CoreLib class__init__ method
: Services are being instantiated, such asEmailCoreLib
,UserDataAccess
,UserService
, andUserPhotosService
.self.email
: An instance of EmailCoreLib is instantiated usinginstantiate_config
function, passingself.config
as a parameter.user_da
: An instance ofUserDataAccess
is created, utilizingSqlAlchemyConnectionRegistry
instantiated fromself.config.core_lib.data.db
.self.user
: An instance ofUserService
is created, passing user_da as a parameter.self.user_photos
: An instance ofUserPhotosService
is created, also passing user_da as a parameter.
init()
core_lib.core_lib.CoreLib.__init__() [source]
When extending CoreLib
class call CoreLib.__init__(self)
to initialize event listeners and set the core_lib_started
flag to False
.
class YourCoreLib(CoreLib):
def __init__(self):
CoreLib.__init__(self)
...
Code Explained:
-The __init__
method of the parent class CoreLib using CoreLib.__init__(self)