I've got a WPF application which uses the MVVM pattern throughout, no code-behind, the ViewModels communicate with each other through the MainViewModel which gets injected into each of them.
Eventually, this application needs to be incorporated into an application which uses Composite Application Library, Unity, etc. Looking through the code and documentation of CAL, I can see how I can register my whole application as a module in the CAL application, but how is my application-as-module going to communicate with the other modules that are also dynamically loaded? I'm expecting, e.g. that each module gets the CAL application somehow injected, or that there is some kind of Event Controller or Messenger with which I can loosely communicate with the other modules, i.e. can send a message and respond to events but not worry if those modules are actually there or not.
How do Composite Application modules communicate with each other?
If you are using CAL(Prism) look into the Event Aggregator/CompositePresentationEvent where it uses the Publisher/Subscriber pattern (aka Pub/Sub) so some Modules of the app is subscribed to an Event Aggregator, so when another Module has changes it will Publish changes e.g.(SelectedItemChanged) to the Event Aggregator, If Other Modules are interested in the changes Published they will act within there part of the application.
Example:
A Desktop e-mail Application:
Modules:
Mail Items (MailID,Subject,Sender,SentDate..etc)
Detail View (MessageBody)
If the selection in the Mail Items ListBox gets changed,It publishes the MailID to the Event Aggregator then Detail View knows about the change and then it grabs the MessageBody for that E-mail by MailID. where "MailItems" and "DetaliView" Modules have been developed by different teams but they have MailID as a common expected message in between.
Check out Prism's event aggregator.
Related
I'm trying to make a module in a prism project. The module doesn't have UI(View, ViewModel). I want the module has working EventAggregator event handlers.
Is there any way?
I wonder it is possible to make service module without view, viewmodels?
Of course, it is. A module is just a late-bound, post-deployment-exchangeable collection of code. It can contain anything, be it views, view models, services, dtos...
I want the module has working EventAggregator event handlers.
... most of those can have dependencies injected because they're resolved from the container. I.e. they can use the event aggregator.
If you have services that are "on their own" (i.e. like a windows service, but in-process) or that need to be initialized early, you can resolve the service in OnInitialized and start it/initialize it.
Getting The Scope of Another Module to Dispatch Events;
Acyclical Directed Communication Network
EDIT: THIS QUESTION IS UNDER REFORMATION.
Intention
What I'm looking to do is fairly straight-forward. I have an Application Core module which looks like this:
var app, application = app = angular.module('app', ['session', 'validation', 'summary', 'participants', 'ngRoute']);
...where each dependency is a module with its own $rootScope (SEE COMMENTS BELOW).
I intend on implementing a Mediator -- not an EventHub. EventHubs are simply a skinny-waist to which subsystems can publish and subscribe to broadcast channels on a specific medium. What I want is a true Mediator -- which, according to GoF, actually manages security of how and where modules communicate, in a unicast model.
That said, I cannot solely rely on using $rootScope.$broadcast/$emit as this will allow any & every module to listen to events from other modules -- without any control or intervention (mediation) from a centralized mechanism.
Problem
The problem arises when there is one module firing an event, say, 'excuseFileLog' and other listening for 'excuseFileLog' -- while the mediator is listening to this event from one module and dispatching it for another. Mediator is listening for one module to say "please excuse the 'FileLog'" and telling another that "an excuseFile has been logged". This is very semantic, as excuse, File, and Log are each, both a verb and a noun. So when Mediator dispatches this same event that it, itself, is listening for -- we enter an Infinite Loop:
// mediator is the sole medium for channels
mediator.on('excuseFileLog', function(){
mediator.fire('excuseFileLog');
});
Solvent
Put simply, I need to be able to access each module's $rootScope and fire events on that module alone -- hopfully, without the need of creating a service that will have to be injected into every module; which will encumber the developer with having to remember to implement the service and creating slightly tighter coupling. If a service is involved, then I may as well implement my own mediator/eventing-system, as apposed to leveraging Angular's eventing system. As the rest of the team is somewhat novice, I would prefer to keep 'chores' to a minimum.
Any help is very appreciated :)
Getting started with Angular, I am trying to implement a toolbar.
The application is structured in a menu bar, a view and the toolbar that form the web-page.
This toolbar has a general purpose (provides help functionality and error display), but for specific views adds some buttons that control the functionality (save, cancel, edit, delete, etc).
In the current design the view and the toolbar are siblings. The view controller depends on the data the view contains, and it can have different functionality. (For example: A view might allow data import, so there will be an import function in the toolbar, while other view might not.)
My problem is I cannot picture the structure of the communication between the view and the toolbar. Because the controllers are tightly coupled a service does not seem to address the communication.
Any help?
You can:
Share data between different controllers/services using rootScope
(use wisely)
You can Publish and Subscribe for app events using
$on, $broadcast and $emit
One good strategy which I have used and helped is to keep all App events definition in one service called something like AppEvents so you can easily keep track of them and control what event causes what from a single place.
Here is one nice article to read that expands more on this topic
I'm working on an application where different widgets from different plugins would be loaded into a host, and they don't know of each other. So I want to use EDP and in one widget raise an event (for example, UserDeleted) and in another widget, subscribe to that event (the famous publisher/subscriber, or let's get more specific, observer pattern).
In jQuery I use trigger() and bind() methods to accomplish this. However, I'm not able to find anything equivalent in Ext JS. Am I missing something? Or is there any other pattern to create loosely coupled UI widgets in Ext JS?
If your widgets don't know about each other, you need to use the mediator pattern.
And it seems that Ext.util.Observable is what you're looking for.
Since ExtJS 4.x Sencha introduced the concept of Controllers which listen for events in a clean systematic pattern of an MVC application. In this scheme your components would fire events (built in or custom ) and controllers will respond to those events.
To fire a custom event you can use fireEvent method on the Observable class which is inherited by just about all other ExtJS classes.
I am used to using Windsor Castle IoC with MVC web applications so I'm a little familiar with registering components and bootstrapping the application.
I am now trying to create my first WPF application and I'm a little lost....
In a typical MVC project I would register all my components in Application_Start in the Global.asax file.
Also, in the Global.asax I would do something like this :
_container = new WindsorContainer();
var myControllerFactory = new MyControllerFactory(_container.Kernel);
ControllerBuilder.Current.SetControllerFactory(myControllerFactory);
In MyControllerFactory which inherits from DefaultControllerFactory I would resolve the Controller given to me, thus all the controllers being used would have their dependencies resolved automatically.
How could I do this in a WPF application ?
I created a class called ContainerBootstrapper that registers my components, and now I'm wondering how I use this in my MainWindow so every time I call a component, it's dependencies are resolved automatically...
Unlike MVC, WPF does not provide framework for decoupled UI development out of the box. There are several out there (such as Caliburn.Micro which implements the MVVM pattern) that sit on top of WPF and provide integration for a variety of IoC containers as well as other features you may find useful in WPF development.
Alternatively, you will need to manage the container directly. i.e. instantiate and initialise the container in App.xaml.cs or MainWindow.xaml.cs and ensure that new object construction via your container's Resolve() function. If it is a non-trivial app, you will probably want to integrate this into your app's navigation routines.