1

我要完成的工作:

  • 根据当前用户的角色加载视图/服务,同时将所有 dll 放在一个目录中
  • 可以多次创建视图(单独的窗口)

我目前使用以下代码从目录加载我的模块:

protected override void ConfigureAggregateCatalog()
{
    base.ConfigureAggregateCatalog();

    AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
    AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(AutoPopulateExportedViewsBehavior).Assembly));

    // Load modules from folder
    // Create Modules folder if it doesn't exist
    string modulesFolder = "Modules";
    if (!Directory.Exists(@".\" + modulesFolder))
    {
        Directory.CreateDirectory(@".\" + modulesFolder);
    }
    AggregateCatalog.Catalogs.Add(new DirectoryCatalog(modulesFolder));
}

我已经尝试四处寻找我正在尝试做的事情的示例,并为 MEF 找到了它们,但没有使用 MEF + Prism,所以我想知道它是否是相同的想法,或者 Prism 是否也有内置的东西。

我已经看到,对于常规 MEF,最好的解决方案(如果这不正确,请纠正我!)是创建自定义导出属性(MEF 导出元数据),例如:

[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
public class UserLevelAttribute : ExportAttribute
{
    public UserLevelAttribute() : base(typeof(IModule)) { }
    public UserLevel User { get; set; }
}

public enum UserLevel    {
    Basic,
    Administrator
}

这是正确的方法还是 Prism 中有什么可以帮助解决这个问题?仅加载用户级别的模块的最佳方法是什么?在常规 MEF 中,我会执行[ImportMany]Lazy加载它们,这对 Prism 是否仍然有效,如果是,我应该在哪里执行?

谢谢

4

1 回答 1

1

实际上,我今天自己正在研究角色管理,并且来自一位开发人员(Guido Maliandi)在 Prism 论坛上的帖子:

Prism 开箱即用不支持身份验证和授权主题。

所以我们必须自己动手,但 Guido Maliandi 发表了一篇博文,展示了一种“Prism v4 中基于身份验证和角色的授权”的方法,该方法利用服务获取模块名称列表以供模块管理器加载。

于 2012-01-06T15:03:17.660 回答