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 worksp开发者_如何学Cace. 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)
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.
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.
精彩评论