Support application factory pattern

See flask documentation for details http://flask.pocoo.org/docs/extensiondev/