drogonframework / drogon

Drogon: A C++14/17/20 based HTTP web application framework running on Linux/macOS/Unix/Windows
MIT License
11.44k stars 1.1k forks source link

怎么在app().run()启动时传参数 到controller层 #1848

Closed 18871434218 closed 9 months ago

18871434218 commented 10 months ago

Notice If you need support or clarification regarding the usage of Drogon in your project, visit the official Drogon support channel at gitter

Please create a new issue only if you think you have found a bug or if have a feature request/enhancement.

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

an-tao commented 10 months ago

你可以创建带参数构造函数的Controller,AutoCreation模板参数置为false,然后手工创建后注册进框架。Routing还可以在controller头文件设置,不影响。如:

image

18871434218 commented 10 months ago

你可以创建带参数构造函数的Controller,AutoCreation模板参数置为false,然后手工创建后注册进框架。Routing还可以在controller头文件设置,不影响。如:

image

但这样是不是意味着每个控制层需要参数都要这样注册传参,而我想要的是注册一个全局参数,然后每个控制层都能自动获取这个

an-tao commented 10 months ago

那你可以自己写个Drogon的Plugin,提供全局参数的接口。或者自己定义个单例,plugin配置装载比较方便