Add plugin system hook function mechanism#1142
Merged
wu-clan merged 6 commits intofastapi-practices:masterfrom Apr 8, 2026
Merged
Add plugin system hook function mechanism#1142wu-clan merged 6 commits intofastapi-practices:masterfrom
wu-clan merged 6 commits intofastapi-practices:masterfrom
Conversation
…ng utilities - Add global LifespanRegistry for dynamic lifespan registration via decorator or direct call - Implement setup_plugins to auto-invoke plugin __init__.setup(app) with logging - Add patching module for runtime middleware and route replacement - Integrate lifespan registry and setup_plugins into app registrar Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
|
优化了部分实现,以更加符合当前以标题为目标的方向 |
Contributor
Author
|
测试了下,没啥问题,lifespan hook和startup hook都ok,然后patching中的replace_middleware好像只有在startup中调用才行,因为到lifespan的时候,fastapi已经可以算是启动了,middleware已经处理了,替换逻辑得换,所以我直接移除函数注释了,本身这个场景就在启动之前最简单。等合并了我就去改下api key plugin |
wu-clan
approved these changes
Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
主要添加lifespan全局注册器,方便插件注入lifespan,添加setup初始化支持,方便插件在启动的时候对fastapi进行一些操作,比如apikey的替换中间件,这样几乎大部分都无须修改原项目,通过插件即可实现。添加一些补丁函数