我正在使用带有应用程序工厂模式的烧瓶。我知道应用工厂模式只在工厂函数中管理配置对象。(如下面的代码所示)
def create_app(config):
app.config.from_object(config)
sentry.init(app)
...
return app
Run Code Online (Sandbox Code Playgroud)
但是如何管理需要该配置但无法在应用程序创建时初始化的额外模块?
所以我想做类似的事情
def create_app(config):
some_module_obj = Module(host=config.host, port=config.port)
app.config.from_object(config)
sentry.init(app)
return some_module_obj, app
Run Code Online (Sandbox Code Playgroud)
而不是
# I don't want to use `config` outside of the `create_app` function!
some_module_obj = Module(host=config.host, port=config.port)
def create_app(config):
app.config.from_object(config)
sentry.init(app)
return app
Run Code Online (Sandbox Code Playgroud)