Reputation: 17425
I have a WPF Prism
solution in VS
and want keep some settings of my prism
module
inside an object in the module project (i load this settings from a file), then i created my prism
module
class (AModule.cs
) like this:
Inside my module project (AModul
project):
[Export]
[Module(ModuleName = "AModule")]
public class AModule : IModule
{
ModuleSettingsModel ModuleSettings { get ; set; }
public AModule()
{
// throw new NotImplementedException();
}
public AModule(IUnityContainer container)
{
// Some codes ....
}
~AModule()
{
// some codes
}
public void Initialize()
{
var regionManager = _container.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion("WorkspaceRegion", typeof(ModuleAView));
ModuleSettings = DataFileManager.LoadModuleData();
}
It works well and i can use my settings inside AModule
Inside Main WPF Project
:
But i need access this settings (ModuleSettings
property) in my Main WPF project
too. For example i need access to ModuleA
»ModuleSettings
in my Bootstrapper
class of my WPF
application. I need do some workd base on each module settings in my main project...
My question is what solutions are there to do? Should i register any type? Where? How?
Note1: ModuleSettings* is inherited from IModuleSettings
and IModuleSettings
is inside Infrastructure project
.
Note2: I load my modules dynamically into prism (my main WPf
project has not any reference to AModule
);
Upvotes: 2
Views: 521
Reputation: 17425
After read GlenThomas answer & @BenediktSchroeder's first comment in question and reading some additional references like this & this, i could found & implement a good way for my question:
I solved it by adding a new custom
Prism Service
ISettingManager
) in Infrastructure Project
. Modules and Main App need reference to Infrastructure Project
SettingManager
)Define one property in ISettingManager
to keep ModuleSetting
like:
Dictionary<string,ModuleSettingsModel> ModuleSettingsPairs{get;set;}
Add some methods in ISettingManager
to Get
, Add
and Remove
setting to/from the ModuleSettingsPairs
dictionary.
Register the new service type in ConfigureContainer
inside the bootstraper
as Singlton
like:
RegisterTypeIfMissing(typeof(IAddonSettingsManager), typeof(AddonSettingsManager), true);
Obtain reference to the IAddonSettingsManager
service instance in the module project
or main app project
, it can do by one of following ways:
Resolve
method of the Unity container
)Get
, Add
and Remove
methods of our service instance (SettingManager
)Upvotes: 0
Reputation: 10764
You should put the ModuleSettings into a class library project that is referenced by the various modules/projects. You could use the singleton pattern to only load and maintain one instance of the settings.
Upvotes: 2