Reputation: 6553
What I'm trying to accomplish:
I currently have my modules loading from a directory using the following code:
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));
}
I've tried searching around for examples of what I'm trying to do and have found them for MEF, but none with MEF + Prism so I'm wondering if its the same idea or if Prism has something built in as well.
I've seen that for regular MEF the best solution (please correct me if this is incorrect!) is to create a Custom Export Attribute (MEF Export Metadata) such as:
[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
}
Is this the correct way or is there something in Prism that helps with this? What is the best way to only load the modules for the userlevel? In regular MEF I'd do an [ImportMany]
and Lazy
load them, is this still valid with Prism, if so, where should I do that?
Thank you
Upvotes: 1
Views: 2945
Reputation: 117
I'm actually looking at role management myself today and from a post on the Prism forum from one of the developers (Guido Maliandi):
The subject of authentication and authorization isn't supported in Prism out of the box.
So we have to roll our own, but Guido Maliandi has done a blog post showing one way of doing "Authentication and role based authorization in Prism v4" which utilizes a service to get a list of Module Names for the Module Manager to load in.
Upvotes: 1