I have a Module for a hardware, which shall be possible to interact from View by the User and from another Module.
Question:
Shall I create a singleton instance in the MyModule_A, register this instance two my container and use this container to resolve the instance in MyModule_B?
Or
Shall I have to use a Eventaggregator two communicate between the two Modules?
The prism documentation is for me not clear in that case.
Solution commanding. Use when there is an expectation of immediate action from the user interaction.
Region context. Use this to provide contextual information between the host and views in the host's region. This approach is somewhat similar to the DataContext, but it does not rely on it.
Shared services. Callers can call a method on the service which raises an event to the receiver of the message. Use this if none of the preceding is applicable.
Event aggregation. For communication across view models, presenters, or controllers when there is not a direct action-reaction expectation.
public class MyModule_A : IModule
{ IRegionManager _regionManager; private IUnityContainer _container; private ILoggerFacade _logger;
public MyModule(IRegionManager regionManager, IUnityContainer container) { regionManager = regionManager; _container = container; } public void Initialize() { _unityContainer.RegisterType<IMyHardware, MyHardware>(new Containercontrolledlifetime); }
}
public class MyModule_AViewModel : BindableBase { private string _title = "MyModule_A"; private readonly IRegionManager _regionManager; private readonly IUnityContainer _unityContainer; private readonly IUnityContainer _unityContainer; private readonly ILoggerFacade _logger; private IMyHardware _myhardware;
public string Title { get { return _title; } set { SetProperty(ref _title, value); } } public MyModuleViewModel(IRegionManager regionManager, IUnityContainer unityContainer) { _unityContainer = unityContainer; _logger = unityContainer.Resolve<ILoggerFacade>(); _myhardware = unityContainer.Resolve<IMyHardware>(); _logger.Log("ViewModel created", Category.Debug, Priority.Medium); } public class MyModule_B : IModule { IRegionManager _regionManager; private IUnityContainer _container; private ILoggerFacade _logger; private IHardware _myhardware; public MyModule(IRegionManager regionManager, IUnityContainer container) { regionManager = regionManager; _container = container; } public void Initialize() { } } public class MyModule_BViewModel : BindableBase { private string _title = "MyModule_B"; private readonly IRegionManager _regionManager; private readonly IUnityContainer _unityContainer; private readonly ILoggerFacade _logger; private IMyHardware _myhardware; public string Title { get { return _title; } set { SetProperty(ref _title, value); } } public MyModule_BViewModel(IRegionManager regionManager, unityContainer unityContainer) { _unityContainer = unityContainer; _logger = unityContainer.Resolve<ILoggerFacade>(); _myhardware = unityContainer.Resolve<IMyHardware>(); _logger.Log("ViewModel created", Category.Debug,Priority.Medium); } }