We are creating a WPF Prism application. We have different developers working on various module projects, and several modules are introduced into the main application shell. The main application is a separate project. We also want to be able to use modules in different applications. We do not want to name regions with the same name in each application.
For example, let's say we have a module that will be used in two different applications. In one application, its developer can name the area of ββthe module "DetailsRegion", and in another, its developer can name it "ResultsRegion".
Each example I can find registers a view with a region by hard-coding the region name in the module class definition:
myRegionManager.RegisterViewWithRegion("RegionNameHere", GetType(ModuleViewType))
What I want to do is put the region name in the app.config application file of the main application and pass that name to the module. Something like that:
In the main application of the app.config shell:
<Modules> <SearchModule> <add key="RegionName" value="SearchRegion" /> </SearchModule> </Modules>
And in the module class file:
Dim settings As NameValueCollection = CType(ConfigurationManager.GetSection("Modules/SearchModule"), NameValueCollection) Dim regionName as string = settings("RegionName") myRegionManager.RegisterViewWithRegion(regionName, GetType(SearchModuleType)
In a sense, this would be the last step to completely separate the modules from the shell and from each other.
This works great in module views . But I cannot do this in the class definition file, since the ConfigurationManager is not available at this level.
I can do this by specifying the region name in the ApplicatonSettings section of the app.config module of the module. But this defeats the goal of storing the module in one place for loading by multiple applications. It really should be in the app.config of the main application.
Is there a way to register a View module with an area without hard coding the region name in the code? We try our best NOT to record anything. Is it really necessary here?