订购由 IoC/插件框架注入的菜单项的最佳方法
我在基于 IoC/插件框架构建的应用程序中看到的常见操作之一是从动态加载的插件向菜单或工具栏添加命令。例如,应用程序的默认插件提供“新建、打开、保存”等操作,这些操作显示在工作区中某个项目的上下文菜单中。新插件可能会添加“邮件、发布、加密”命令,但这些命令与“新建、打开、保存”相关的命令显示在哪里?
通过 IoC 加载组件的应用程序如何对注入的项目强加顺序?
- 它是否需要来自插件的元数据来提示如何对项目进行分组或排序?
- 它是否使用先前已知的菜单名称(或 ID)的配置文件来定义顺序(对我来说似乎有点弱)?
- 或者“未知”插件是否被视为二等公民并且总是被转储到子菜单中?
- 我从未想象过的东西(我希望在答案中看到)
One of the common things I've seen done in applications built on IoC/plugin frameworks is to add commands to menus or toolbars from the dynamically loaded plugins. For example, the application's default plugins supply actions like "New, Open, Save" that show up in the context menu for a certain item in the workspace. A new plugin may add "Mail, Post, Encrypt" commands, but where do those commands show up in relation to "New, Open, Save"?
How can the application that is loading components through IoC impose order on the items that get injected?
- Does it require metadata from the plugins that give a hint on how to group or order the items?
- Does it use a config file of previously known menu names (or ids) to define the order (seems a little weak to me)?
- Or are "unknown" plugins treated as second class citizens and always get dumped into sub menus?
- Something I've never even imagined (which I'm hoping to see in the answers)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您基本上可以向商品索取订单。
我的意思是你定义了四个块(1.新建和打开,2.保存,3.打印,4.退出)。插件现在可以告诉应用程序有首选块。例如,一个插件想要添加打印功能,因此它为块 3 提供了优先选项。
You could basicly ask the items for an order.
I mean you define lets say four blocks (1. new and open, 2. save, 3. print, 4. quit). The plugins now can tell the app there prefered block. E.g. One plugin wants to add printing capabilities so it gives it pref for block 3.
我不知道这在其他框架中是如何完成的,但我可以解释 Mono.Addins 如何支持它。使用 Mono.Addins 您可以声明菜单的扩展点。加载项将能够在其上注册命令。诀窍在于扩展(在本例中为命令)可以有一个标识符,并且在注册扩展时,您可以指定另一个扩展的标识符,该扩展必须插入到该标识符之后或之前。
I don't know how this is done in other frameworks, but I can explain how Mono.Addins supports it. Using Mono.Addins you would declare an extension point for the menu. Add-ins would be able to register commands on it. The trick is that extensions (commands in this case) can have an identifier, and when registering an extension you can specify the identifier of another extension after or before which it has to be inserted.