Attaching serialized data to Modules

Topics: Prism v4 - WPF 4
Feb 17, 2011 at 6:25 PM
Edited Feb 17, 2011 at 6:26 PM

I currently initialize my modules using a UnityBootStrapper. The bootstrapper gets a list of ModuleInfos by deserializing(from a xml file) a list of ModuleInfos and the module infos are added to the ModuleCatalog. The modules are instantiated and initialized by the bootstrapper and thats all good. My question is, how do I then inject custom data(deserialized from a file) that belongs to a specific module. For example I have a class below;


public class ModuleA : IModule
	public List<string> NameList {get;set}




What would would be the right practice for me to inject an existing(deserialized) NameList to ModuleA? 

I read up on Annotating Objects into Constructor;


Annotating Objects into Properties;


but im still missing something here because how do I match the serialized data with a particular module that will be initialized by the UnityBootStrapper based on whats in the ModuleCatalog.

Is there anywhere I can attach data to a ModuleInfo(or even a custom IModuleCatalogItem) that 'somehow' the ModuleCatalog in the UnityBootstrapper knows how to create the module and inject the custom data onto the modules property.

This would seem like a common problem because how else would you specify the region name of a shell that you want your view to inject onto during module.Initialize()? I definitely dont want to hardcode the region name. Wouldnt it be nice if you can somehow easily set that in a xaml file or configuration file that specifies a region name for the module to mount that view onto?

Any help would be appreciated.

Feb 17, 2011 at 7:45 PM
Edited Feb 17, 2011 at 8:04 PM

Would having a custom IModuleInitializer work in this?

Do you think for my case, a better approach would just be deserializing the modules(different module types that implements IModules) itself and use BuildUp to buildup the other necessary properties I use like the UnityContainer, RegionManager and EventAggregator? In this case, my modules will have all the deserialized data with it.

Feb 18, 2011 at 3:44 PM


One possibility in order not to hard code the region names would be to define constants for the region names in an infrastructure project (one that would be referenced by your shell and all your modules).

As for the approach for deserializing your data, I wouldn't recommend to place such logic in the IModule class. One possibility for that would be to place the logic for deserializing your data in the component that will be responsible of handling it, such as a controller or a service.

If you scenario strictly requires you to place that logic inside the IModule, the approach you're mentioning in your second post seems to be a valid one.

I hope you find this helpful.

Guido Leandro Maliandi

Feb 18, 2011 at 4:33 PM

Thank you very much for your suggestions Guido. I will have to think abit more here in terms of how I would design my infrastructure.