Hi there. I am currently writing an application which speaks to ActiveDirectory with the LDAP3 library. I would like to establish a single connection to the server, and then have all the other modules be able to do various operations on the server, using that persistent connection. Would it be best to use a Singleton class, or to pass a connection object around? I am unsure of how best to approach this, and am getting confused when looking at the different ways it could be done.
At the moment I have a main module, which creates a connection:
LDAPConnection = ldap3.Connection(LDAPServer, user=config.LDAPUser, passsord=config.LDAPPassword, auto_bind=True)
In later code, I wish to user a function from handlers.py:
from handlers import processFile processFile(incomingFile)
The code in handlers/processFile() needs to be able to use the LDAPConnection which was created in the main module of the application. How to do this?