Use **kwargs in class constructor

Asked by LeGid on 2015-07-27

I was wondering if it's possible to pass **kwargs to a class that contains the service methods. Or is there an other way to get environment variables from the class constructor (e.g. to pass the path to a config file)?

Question information

English Edit question
ladon Edit question
No assignee Edit question
Last query:
Last reply:
jsgaarde (jakob-simon-gaarde) said : #1

Service class instances are created before any request hit methods. And only one instance of each service is created on each process. Therefore it's not possible to pass the wsgi environment to a service class constructor. I recommend that you create a non-ladonized method in your class which you call at the beginning of your service methods to pass your enviromnent. If the environment parsing you need to do is the same for all service classes and methods I recommend that you implement a global function or decorator in a separate module.

Best regards
Jakob Simon-Gaarde

Can you help with this problem?

Provide an answer of your own, or ask LeGid for more information if necessary.

To post a message you must log in.