Shazter
Shazter

Reputation: 305

DI Unity AssemlyInformation.Title ModuleAttribute.ModuleName and load module on demand/from directory

i started to work with prism + unity DI. I have two problems and questions until now.

1. Problem/Question

I would like to use the AssemblyInformation Title as ModuleAttribute.ModelName.

Problem: This doesnt work:

[Module(ModuleName = AssemblyName.GetAssemblyName(Assembly.GetExecutingAssembly().FullName).Name)]

This works well.

[Module(ModuleName ="Module1")]

Question:

Is there any possibility to use AssemblyInformation.Title as ModuleAttribute.Modulename?

2. Problem/Question

I would like to load on demand from Directory my Modules, but only modules which has a special prefix in the module name.

Problem:

If I check my ModuleCatalog, then is still empty before I initialze the modules.

Question:

Is it possible to check before module init the name of the module, because I do not want to exeute the method Initialize() inide of the Module.

My Bootstrapper:

    protected override IModuleCatalog CreateModuleCatalog()
            {
                return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
            }

            protected override void ConfigureContainer()
            {
                base.ConfigureContainer();
            }

            protected override void InitializeModules()
            {
                ModuleCatalog moduleCatalog = (ModuleCatalog) this.ModuleCatalog;
// Here I would like to discover my modules with special modulename prefix. 
//If the prefix is not found, then I dont want to init the module.

                try
                {
                    base.InitializeModules();
                }
                catch (DuplicateModuleException e)
                {
                }
}

Module:

    [Module(ModuleName = "MyPrefix-Module1")]
        public class PrismModule1Module : IModule
        {
            IRegionManager _regionManager;

            public PrismModule1Module(IRegionManager regionManager)
            {
                _regionManager = regionManager;
            }

            public void Initialize()
            {
               Debug.WriteLine("Module init");
            }
        }

Upvotes: 0

Views: 37

Answers (1)

dvorn
dvorn

Reputation: 3147

  1. There is no such built-in functionality and cannot be because in general module is a class (implementing IModule interface) and an assembly may contain several modules.

This is achievable, however, by overriding the default implementation.

  1. You need to mark modules as loaded on-demand. You need to initialize the catalog so that module information has been read (about on-demand loading). Then you may query module information and actually load the modules.

Upvotes: 1

Related Questions