Hey everyone,
I want to write a little web application. I got several views which all need access to the database. But of course I don't want to start a new session in all of them and besides it would be useful to abstract things in models. So if I don't want to pass a database object to every view function (which wouldn't be possible anyway as my views are called by an independant router) I have to use a global variable for my database object.
If I'm not totally wrong this means I have to open a session in my apps init() in order to catch errors. But at the end of my main() the session must be closed again. So I have to store my session in a global variable, too. This somehow seems like an ugly mess and as soon as I want more databases or sessions to be available in all my views it starts becoming error-prone.
Furthermore global variables are the pure evilness anyway (that's what people use to say from time to time).
So has anyone an idea how to get out of this misery. (Sorry if my problem is not 100% mgo-related.)