New Posts New Posts RSS Feed: Automatically Resolve Modules
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Automatically Resolve Modules

 Post Reply Post Reply
Author
smi-mark View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 24-Feb-2009
Location: Dallas, Texas
Posts: 343
Post Options Post Options   Quote smi-mark Quote  Post ReplyReply Direct Link To This Post Topic: Automatically Resolve Modules
    Posted: 23-Oct-2009 at 1:51pm
Figured this may be helpful to people working with Prism.

        protected override Microsoft.Practices.Composite.Modularity.IModuleCatalog GetModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog();
      
            foreach(var type in GetTypesImplementingInterface(typeof(IModule)))
            {
                catalog.AddModule(type);
            }

            return catalog;
        }

        public static IEnumerable<Type> GetTypesImplementingInterface(Type desiredType)
        {
            List<Assembly> assemblies = new List<Assembly>();
             foreach (AssemblyPart ap in Deployment.Current.Parts)
             {
                 StreamResourceInfo sri = Application.GetResourceStream(new Uri(ap.Source,UriKind.Relative));
                 assemblies.Add(new AssemblyPart().Load(sri.Stream));
            }

            return assemblies.SelectMany(assembly => assembly.GetTypes()).Where(type => desiredType.IsAssignableFrom(type) && type.IsClass);
        }
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down