基于用户权限的 MEF 组件
几个月前,我迈出了迈向 MEF 的第一步,到目前为止一切似乎都还不错。我想做的是在我的实际应用程序中使用 MEF 并加载,或者我们可以说基于经过身份验证的用户权限显示 UI 组件。我正在为诊所开发患者管理系统,我想实现根据用户类型显示 MEF 组成的 UI 组件的场景。例如,如果经过身份验证的用户是医生,我想显示特定组件并隐藏其他组件。
我想要实现的目标是
ISystemComponent
,它具有一些属性和方法,以便管理可以控制每个用户访问级别,并根据数据库记录 MEF 组成的控件将显示给最终用户。我还考虑在导出组件时使用元数据接口,那么使用它如何才能获得所需的结果?
任何正确的方向将不胜感激
I did my first steps toward MEF few month ago and everything seemed to be okay till now. What I want to do is to use MEF in now of my real applications and load or we can say display UI components based on authenticated users permissions. I am developing patient management system for clinic and I want to implement scenario where MEF composed UI components are displayed based on user type. for example if authenticated user is doctor I want to show particular components and hid others.
What I am trying to achieve is something like
ISystemComponent
which has some properties and methods so administration can control each user access level and based on DB records MEF composed controls will be displayed to the end-user. I also think of using MetaData interface while exporting components so using this how can I get the desired result?
any right direction will be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我通过使用模块 ID 的元数据属性和具有权限的表来完成此操作。
在接口上执行 ImportMany,然后使用反射根据元数据属性对其进行过滤,并与表中的权限进行比较。
这篇博文描述了所有涉及的 MEF。
http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/01/20/mef-for-beginner-metadata-part-8.aspx
其他链接。 .
http://博客。 microsoft.co.il/blogs/bnaya/archive/2010/01/09/mef-for-beginner-toc.aspx
http://mef.codeplex.com/wikipage?title=Exports% 20and%20Metadata&referringTitle=指南
具有安全性和配置文件效率的 MEF 插件
带有 ImportMany 和 ExportMetadata 的 MEF
这将显示如何导入来自xaml
http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/03/20/mef-for-beginner-import-from-xaml-part-11.aspx
I did this by using an metadata attribute for a module ID and a table that has the permissions .
Do a ImportMany on the interface then filter it based on the metadata attribute using reflection and compare to the permissions in the table.
This blog post describes all the MEF involved.
http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/01/20/mef-for-beginner-metadata-part-8.aspx
Other Links..
http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/01/09/mef-for-beginner-toc.aspx
http://mef.codeplex.com/wikipage?title=Exports%20and%20Metadata&referringTitle=Guide
MEF Plugins with Security and Profiles Efficency
MEF with ImportMany and ExportMetadata
This will show how to import from xaml
http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/03/20/mef-for-beginner-import-from-xaml-part-11.aspx
此处一文详细介绍了如何使用 AOP 将安全问题注入 MEF。这可能是实现此目的的一种方法 - 我还没有在 MEF 中找到任何可以在其他地方实现此类功能的内容。
The article here details using AOP to inject security concerns into MEF. This could be one way of doing this - I havent' found anything in MEF that would allow this sort of functionality elsewhere.
我认为 PRISM 完全可以实现您所描述的功能。请查看这篇代码项目文章。您可以创建多个模块目录(根据用户权限),并按照描述从 XML 动态加载目录 这里:
I think PRISM can do exactly what you've described. Take a look at this Code Project article. You can create several module catalogs (according to user permissions), and load catalog dynamically from XML as described Here:
我使用 Cinch 和将控件映射到的后端 SQL 表在 WPF / MVVM 中实现了此功能角色和查看权限。这允许您通过视图模型控制权限并随时更改可见性。
Cinch 协助完成 MVVM 的一些苦差事,同时允许您通过 MeffedMVVM 或 Prism。
I implemented this in WPF / MVVM using Cinch and backend SQL tables that mapped controls to roles and view permissions. This allows you to control permissions through the viewmodel and change visibility at any point.
Cinch assists with some of the drudgery of MVVM while allowing you to leverage MEF through MeffedMVVM or Prism.