简体   繁体   中英

Program architecture with PRISM Modules and MVVM

I am unsure how to structure a large program using PRISM Modules.

I have created the following layers:

Repository BusinessLayer -> IUnityContainer registering services UILayer -> MVVM implemented

If I have 3 modules, and I have an action in one of them, how do I trigger the view of another module to load?

I am currently using the EventAggregator but this requires the viewmodel to be somehow loaded already so it can subsribe to the event.

Ideally, I think, I would like to do something like the following:

IOrderService service = UnityContainer.Resolve(); service.PlaceOrder();

The order service is then responsable for loading the relevant UI features and registering it with the RegionManager.

Is that correct or have I got this completely wrong?

Thanks

I actually like both of your approaches, but which one to use really depends on your requirements. If you want to explicitly have one module tell another module what to do, then service locator is the way to go. However, that approach has the tendency to bring some level of tight coupling across your modules.

If tighter coupling is not what you want (for example, what happens when you add a fourth module that needs to handle the action?), then the event aggregator can get you the looser coupling. This approach does require a little more rigor and up-front work to manage regions, etc, as it's easy to end up with a somewhat unmanageable set of events that lead to debugging difficulties (I've got that problem now in a project).

Kind of a nebulous answer, but I hope it helps :-)

Nate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM