0

I want to create two modules that describes toolbar and menu feature, but I don't want to define them in two different assemblies, and I tried to do it in that way,It works fine,but I'm afraid that would it takes twice as much as memory like just define them in one module? Follow is my demo code, they're written in one project.

public class MainMenuModule : IModule {
        public void Initialize() {
             RegionHelper.RegisterViewWithRegion(Shell.RegionNames.Menu, typeof(Views.Menu));
        }
    }

 public class ToolBarModule : IModule {
        public void Initialize() {
            RegionHelper.RegisterViewWithRegion(Shell.RegionNames.ToolBarRegion, typeof(Views.ToolBar));
        }


    }

Note that RegionHelper is a wrapper prism region API.

Jake
  • 28
  • 6

2 Answers2

1

That's fine. Although I don't really see a use case for two modules in one assembly...

And btw, the module definition classes are ready for collection once their Initialization methods return.

Haukinger
  • 10,420
  • 2
  • 15
  • 28
  • Thanks for your answer,about the reason why I want it to do it that way---For UI sperately designed and compostited at runtime while modules are being initialized,I think somethings like toolbar and mainmenu could be designed as totally differently services for better testable,some projects did do it in this way,like[https://github.com/0xd4d/dnSpy](even though they don't use Prism,but I really appreciate their way.) – Jake Jan 31 '18 at 03:31
1

Is it OK to put two Prism modules in a single assembly? Well, yes. It will work and there is nothing stopping you from really. You can put as many module classes in a single assembly as you want to.

Keep in mind that a module is supposed to be a set of loosely coupled functional units though. If you put two modules in a single assembly, you can no longer load the first one without also loading the second one and vice versa. This may be a problem or it may not depending on how the modules are used by your application.

The possible down-sides of using too many assemblies are discussed here: Specific down-sides to many-'small'-assemblies?

This is generally not an issue.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thanks for your answer!I am using mef and prism to build my project,I just want to navigate some region of the mainview to different views and bla bla,but I think it's weriod to do such things in a module which may be called "MainModule"---mainview should never know about subviews, and I can't find elsewhere to initialize my views while the initialization is being executed,so I made more modules in one assembly and Prism MEF will automatically find any module that marked as [ModuleExport]. – Jake Jan 31 '18 at 03:44