Hi there, Just some background on myself, I've been a c# guy for quite a few years, but have just started to move across to python the last couple of months.
I started on python 3, and am used to using other DI frameworks in c#, using constructor injection.
I have a library which does all of my business logic, and uses use_annotations, to inject. All works fine.
One of my objects I pass in is my Database object.
I now have a need to use the same library ,but for two different databases. Each database is for a different company, but I'll need to merge data from both.
I just can't seem to get my head around how I can achieve this. At this stage I'm using flask injector, and for example have the following setup:
def configure(binder):
db = CLDB(db_username=app.config['QUANTUM_USERNAME'],
dsn=app.config['QUANTUM_DSN'],
db_password=app.config['QUANTUM_PASSWORD'],
logger=app.logger,
quantum_username=app.config['QUANTUM_MASQUERADE_USER'])
# set it up as a singleton.
binder.bind(CLDB,
to=db,
scope=singleton
)
injector = Injector(auto_bind=True,
modules=[configure],
use_annotations=True)
FlaskInjector(app=app,
injector=injector)
then I have a separate library that has classes like:
class MSCIssuer:
def __init__(self,
db: CLDB,
emailer: Emailer,
logger: Logger):
self._db = db
self._emailer = emailer
self.logger = logger
now say in my merged project I want to instantiate two instances of MSCIssuer.
One with CLDB object 1, and one with CLDB object 2, each with different configurations.
Since I haven't used guice before I'm kind of stuck :(
Thank you.
Hi there, Just some background on myself, I've been a c# guy for quite a few years, but have just started to move across to python the last couple of months.
I started on python 3, and am used to using other DI frameworks in c#, using constructor injection.
I have a library which does all of my business logic, and uses use_annotations, to inject. All works fine.
One of my objects I pass in is my Database object.
I now have a need to use the same library ,but for two different databases. Each database is for a different company, but I'll need to merge data from both.
I just can't seem to get my head around how I can achieve this. At this stage I'm using flask injector, and for example have the following setup:
then I have a separate library that has classes like:
now say in my merged project I want to instantiate two instances of MSCIssuer.
One with CLDB object 1, and one with CLDB object 2, each with different configurations.
Since I haven't used guice before I'm kind of stuck :(
Thank you.