Lord of the Presenters - Return of the Event Lifecycle
Presenter Question
I just can't get enough of the titles, lol. Another doubt has arrived concerning the new Presenter Infrastructure, and I quote:
I got the idea now, sounds interesting... But I couldn't see an immediate usage, since there won't be any forced logging, and validation is not performed like that. There's an example of attribute that you imagine to have, and what effect will it have in the presenters?
If I got it right, by having an attribute the NMVP Engine will generate events of that kind for the presenter. To subscribe the events you'd necessarily have to have methods (On_XXX), and for that, wouldn't it be easier to detect if the presenter wants or not the behavior by simply checking if he subscribed to the event? (that is, ALL events are always generated, it's up to the presenter to use whichever it needs...).
The emphasis is mine, you'll see why in a moment.
I guess that should be a pretty common doubt, so once more I'll tackle each doubt one at a time.
You're absolutely right. There won't be any forced logging, as there won't be any forced validation, and any forced anything for that matter. It's up to the developer to specify what he wants. Now IF he specifies that a presenter IS log enabled, then there will be logging BY ALL MEANS. At least if I am the one developing the LOG Plugin (you could always use somebody else's, or just implement your own).
That's exactly what I'm trying to achieve here with the new Presenter Infrastructure. Extensibility. Let's say you want to cancel Save if your view does not pass validation. All you'd have to do is place both ValidatingPresenter and PersistentPresenter attributes, since they can talk to each other. The PersistentPresenter recognizes if the current Presenter has the ValidatingPresenter Plugin and then if it does, calls on the Validate method before saving. The ValidatingPresenter Plugin now is in charge and performs validation in two steps: Validates the view using the Validation Everywhere framework AOP Validation, and then call on the Validate method for the presenter if it is implemented. If Validation fails then the saving is aborted, and you didn't code A LINE for it.
Now that's just one sample of Plugins integration. There'll be lots more, or at least I hope for it. I hope I cleared how the Plugins can influence the presenter. Now onto the bold part of the question.
Why can't I generate ALL events and let each presenter hook up onto the ones they need? Because I don't have the faintest IDEA of what events there will be. Or the order in which they'll fire. Or how they interact. Let's take the Save events for example.
This is how I envision the lifecycle so far.
User clicks the Save button in the UI. The Web Form (or controller or whatever) calls the HostPresenter.GetPlugin<PersistentPresenter>().Save() method, which in turn calls every single presenter's PersistentPresenter Plugin's Save method. Each Save method, in turn, raise the OnBeforeSave event. At this point anyone who subscribed to that event will receive a notification and be able to cancel the save (via a CancellableEventArgs).
After that the Save() method is called on the presenter. When the saving is done, OnAfterSave is called and once again whoever subscribed to it will get notified. This way the presenters get integrated without even knowing that they're integrated.
For the user of the framework, the only code he'd write is the line that calls the HostPresenter to invoke the Save method, and each Save method in each presenter (the business logic to persist the view).
I'm still thinking on how to hook events among Plugins, since I don't want to couple them together, so we don't get the "IF I USE PLUGIN XYZ, THEN I MUST USE XYZ2", but that's subject for another topic.
So actually, my friend, you got that right. Each Plugin WILL subscribe to each other's events if need be. And presenters will be able to subscribe to their own Plugins events if need be. Talk about extensibility and flexibility huh?
Stormwind Community
As a side note, I've started building the Stormwind Community Server. I'll be using Amazon's Elastic Computing Cloud (EC2) to host the server. The server will run Fedora 7 with Windows 2003 virtualized (for the Build Server and .Net compilation). Since I'm a newbie in Linux Administration I'd like to know if there's someone out there willing to join the project and help me out here. What I'm saying is that I want a Community Administrator. Please anyone who whishes to apply send me an e-mail at heynemann at gmail. If you know how to virtualize windows 2003 in Linux, and how to configure IIS and Apache, that's a plus. We'll probably be needing to integrate some services like Forum, wiki, etc. They'll probably all run in Windows 2003, so we can integrate each service via .Net.
I have some consistent ideas so far on what I want to achieve with the community, so I'd love to discuss them with interested parties. But please only apply for it if you intend to dedicate some time to the job. I want to build and active community, not just another website with last update dating to 2003.
#114