Tuesday, April 15, 2008

I'm building a small sample for EFContrib, and thought it would be cool to use the new MVC framework 'Prism' for it. Prism is a new framework currently under development by the patterns and practices group. It is not feature complete and everything might change in the next drop. But, well, it's fun to see such a framework develop and how best to understand it, than by building something simple with it!

I'm trying to do something fairly basic: I have a view that has a button on it. If the button is pressed, a form should popup where we can search for employees. When the search is over, the result should be accessible by my controller.
At the same time though, I know that I'm going to have a detail screen as well with the same button on it. Here the button chooses a teamleader for the employee.

I want to define the command once, but need my controllers to behave differently. It's quite possible that I would be better off just creating two commands (one for the detail screen and one for the employee screen). You could argue that they perform different actions: choose an employee versus choose a teamleader.
But I don't swing that way and I feel it should be possible to have the same command on a lot of buttons and let the appropriate controller deal with it.

In the prism project are a few base classes for commands: the DelegateCommand and also the ActiveAwareDispatchCommand. As far as I can see, they allow a command to be hooked up by multiple views and allow controller to register their interest in them.
I created a static class with my 'ChooseEmployee' command:

 

    public static class EmployeeChooserCommands
    {
        public static ActiveAwareMultiDispatchCommand ChooseEmployee = new ActiveAwareMultiDispatchCommand();
      }

Now, my views couple their buttons to this command in the regular way.

In my definition of MVC a controller is responsible for the logic and thus handles this command.

        protected ActiveAwareDelegateCommand chooseEmployeeCommand;

It defines it's own command and in the ctor hooks it up:

            chooseEmployeeCommand = new ActiveAwareDelegateCommand(Choose, CanChoose);
            // register this instance on the global
            EmployeeChooserCommands.ChooseEmployee.RegisterCommand(chooseEmployeeCommand);

The last line will make this controller react to executions of the command by every source.

This is the pattern that I see in the current Prism reference implementation project.

The fun thing about the ActiveAwareDelegate is the way you can set it as Active and not-Active. If it is not active, it will not be queried for canExecute information and its execute delegate will not be called.

So, what I did, was to let my views implement the IActiveAware interface and throw an event when they lose or get focus. The corresponding controllers react to it in this way:

        void view_IsActiveChanged(object sender, EventArgs e)
        {
            chooseEmployeeCommand.IsActive = view.IsActive;
          }

Setting the command to only be active when the view is active.
Downside here is that if one view is active, it gets to decide on the canExecute result, but all buttons in all views will react to it: clearly not what we want.

So, I feel I'm on the wrong track here. I really miss being able to set some sort of 'affinity' to the RegisterCommand method. I would like to let that method know I'm interested in commands where the source is equal to my view. But then again, maybe I should just create different commands :-)

Monday, May 24, 2010 9:43:45 AM (Romance Standard Time, UTC+01:00)
cheap mbt shoes online seller.
Wednesday, September 29, 2010 4:29:53 AM (Romance Standard Time, UTC+01:00)
Every one who love the mbt shoes will love the <a href="http://www.mbt-usa.com/mbt-moja-c-49.html">mbt moja</a> and the <a href="http://www.mbt-usa.com/mens-mbt-shoes-c-10.html">MBT Men's Shoes</a>,it's so welcome ,and the <a href="http://www.mbt-usa.com/mbt-habari-sandals-new-c-35.html">mbt sandals</a> is also hot saling in my shop .Pls don't wait and to order one.
Wednesday, September 29, 2010 4:30:40 AM (Romance Standard Time, UTC+01:00)
browsing Mbt shoes on web pages of Mbt, you will find that MBT Tataga will be a good choice.
Wednesday, September 29, 2010 4:31:24 AM (Romance Standard Time, UTC+01:00)
People like go to buy coach outlet buy Coach Hoho Bags by coach hangbags quality stuff, a bag you can use for a long time, coach hangbags walking on the road has fashion sense.
Wednesday, September 29, 2010 4:32:19 AM (Romance Standard Time, UTC+01:00)
In the uggs sites, the ugg sale have the two styles of the boots, the UGG Ultra Tall and the UGG Classic Short. They are included mostly of the boots.
Thursday, October 14, 2010 2:45:43 PM (Romance Standard Time, UTC+01:00)
<p>Of the 30 million in the <a href="http://www.fivefingeronline.com/">vibram fivefingers</a> activities, 2010 non-environment-majors on China walk first stage <a href="http://www.fivefingeronline.com/">vibram five</a> activities, the poem ended Co., LTD. Offers outdoor products to both the retail price is lucky <a href="http://www.fivefingeronline.com/products_all.html">five finger</a> skywalker prize for ¥1980 German professional outdoor shoe in <a href="http://www.fivefingeronline.com/featured_products.html">vibram shoes</a> on GTX RENEGADE for hiking shoes. They will be wearing this pair of the world’s most powerful boots origin produces the boots top <a href="http://www.fivefingeronline.com/featured_products.html">five fingers</a> product officially began to walk.Called “outside” of the ID of the winners is walking <a href="http://www.fivefingeronline.com/products_new.html">vibram five finger</a> across the big horqin sandy land “green channel”. Inner Mongolia horqin sandy land and <a href="http://www.fivefingeronline.com/vibram-five-fingers-kso-c-67.html">fivefingers kso</a> liaoning, jilin across three provinces, 92% of eastern Inner Mongolia above <a href="http://www.fivefingeronline.com/products_new.html">vibram five fingers</a> distribution in chifeng city, area and the tongliao 5 million square <a href="http://www.fivefingeronline.com/specials.html">vibram five fingers shoes</a> kilometers, ranking first in four sand. Genghis khan’s <a href="http://www.fivefingeronline.com/vibram-five-fingers-kso-c-67.html">vibram kso</a> brother, and its subordinate subordinates’ called cheap five finger shoes, then formed by <a href="http://www.fivefingeronline.com/vibram-five-fingers-classic-c-76.html">vibram classic</a> tribe.In the first stage, the activity ended at the second stage, the second phase will start to Tibet, xinjiang, “stand in xinjiang, ningxia, Tibet, shaanxi, gansu, qinghai and within the <a href="http://www.fivefingeronline.com/vibram-five-fingers-flow-c-73.html">vibram flow</a> scope of land.</p>
<p>If you want to take part in outdoor activities, persistent and very love this <a href="http://www.fivefingeronline.com/vibram-five-fingers-kso-c-67.html">vibram fivefingers kso</a> sport, so choose cheap vibram is very important. A set of suitable equipment can indeed for our outdoor activities to provide protection, let us be more close to nature, feel nature.We choose to suit <a href="http://www.fivefingeronline.com/reviews.html">5fingers</a> oneself is suitable for environmental equipment, so we first concern is the applicability of the equipment, rather than spend less money for price, event, although is good, but usually sale <a href="http://www.fivefingeronline.com/vibram-five-fingers-speed-c-115.html">five finger speed</a> is reality, the most expensive sometimes are not is most appropriate. There is not expected to equipment can be armed to the teeth. A bite to eat dinner.</p>
<p><a href="http://www.fivefingeronline.com/">MBT shoes</a> have become increasingly popular. Because of its tremendous role to humans. <a href="http://www.fivefingeronline.com/products_all.html">mbt walking shoes</a> not only fashionable, but also healthy. I think this is more important is fashion. Swiss <a href="http://www.fivefingeronline.com/specials.html">mbt shoes sale</a>, Karl Mueller invented. His invention came to the United Kingdom. In tourism this journey, it can be found wearing <a href="http://www.fivefingeronline.com/products_new.html">mbt sale</a> can easily get ahead, he who is like a walk in the soft grass. It takes years of research and development, <a href="http://www.fivefingeronline.com/reviews.html">mbt shoes review</a> Sale market development began in 1996, selling over one million every year is growing <a href="http://www.fivefingeronline.com/">mbt footwear</a> rapidly.<a href="http://www.fivefingeronline.com/">http://www.fivefingeronline.com/</a> </p>
Thursday, October 14, 2010 2:48:31 PM (Romance Standard Time, UTC+01:00)
3_103.html"><strong> </strong></a> are made more unique by the inclusion of a large wooden button with the Ugg logo on it and an elastic band closure. So it allows you to wear t
Just as with the <a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-cardy-c-53_108.html"><strong>UGG boots</strong></a> the new calf high boot that this <a href="http://www.shoeslockers.com/ugg-boots-ugg-knightbridge-boots-c-53_118.html"><strong>Ugg Australia</strong></a> company have introduced the Bailey Button offers the same level of comfort. Certainly for women who are looking for a pair of <a href="http://www.shoeslockers.com/ugg-boots-ugg-lo-pro-button-c-53_124.html"><strong>UGG sale</strong></a> to team with jeans or a long skirt these are ideal.But as you will soon discover these <a href="http://www.shoeslockers.com/ugg-boots-ugg-bailey-button-c-5hem with this detailing on shown or you can undo the button and then turn the top over to create a cuff.With all the boots included in <a href="http://www.shoeslockers.com/ugg-boots-ugg-new-style-ultra-short-boots-c-53_122.html"><strong>Cheap UGG boots</strong></a> Australia’s Classic Collection range the <a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-mini-c-53_114.html"><strong>UGG bailey button</strong></a> is lined with twin faced Grade A sheepskin. Also there is the traditional suede heel guard to ensure that not only is this area protected but offers this part of the <a href="http://www.shoeslockers.com/ugg-boots-ugg-bailey-button-fancy-c-53_102.html"><strong>UGG boots sale</strong></a> support. Plus within the <a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-short-c-53_113.html"><strong>UGG classic cardy</strong></a> you find each pair has sock liners that are made from sheepskin PU foam so increasing the level of comfort a person feels when wearing <a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-short-c-53_113.html"><strong>UGG short boots</strong></a>.<a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-tall-c-53_110.html"><strong>zigtech shoes</strong></a> is very unique. It uses an innovative lightweight foam materials,<a href="http://www.shoeslockers.com/reebok-zigtech-shoes-c-127.html"><strong>ZigTech trainers</strong></a> are designed to help you run further and faster, allowing you to train while using their unique <a href="http://www.shoeslockers.com/reebok-easytone-shoes-c-126.html"><strong>Easytone shoes</strong></a> harder for longer with reduced risk of injury. They do this by providing lots of cushioning Yesterday we saw the promo video featuring Thierry Henry and Lewis Hamilton talking about the trainers. So today we’re looking at the latest technical video released by Reebok to explain what <a href="http://www.shoeslockers.com/women-mbt-shoes-mbt-fora-shoes-c-49_61_66.html"><strong>Discount Reebok Easytone</strong></a> is and how the <a href="http://www.shoeslockers.com/ugg-boots-ugg-knightbridge-boots-c-53_118.html"><strong>zigtech sale</strong></a> sole works.in the Slinky-esque midsole/outsole that is said to reduce muscle wear and transfer energy. <a href="http://www.shoeslockers.com/ugg-boots-ugg-lo-pro-button-c-53_124.html"><strong>Reebok zigtech shoes</strong></a> Stadium bring an innovative technology shoes- <a href="http://www.shoeslockers.com/men-mbt-shoes-mbt-casual-shoes-c-49_54_55.html"><strong>Reebok easytone shoes</strong></a> training run. We series, is the best <a href="http://www.shoeslockers.com/products_new.html"><strong>Easy tone shoes</strong></a> sport technology to date. It can reduce 20% of the leg muscle fatigue and wear, in order to cultivate strength and degree of difficulty is significantly increased.<a href="http://www.shoeslockers.com/men-mbt-shoes-mbt-sandals-shoes-c-49_54_57.html"><strong>MBT shoes</strong></a> effect abdominal, leg and buttock muscles.cheap <a href="http://www.shoeslockers.com/mbt-shoes-men-mbt-shoes-c-49_54.html"><strong>Cheap mbt shoes</strong></a> looks sunny, so it is a good choice <a href="http://www.shoeslockers.com/mbt-shoes-c-49.html"><strong>MBT shoes sale</strong></a> believe that human fitness majestic, <a href="http://www.shoeslockers.com/skechers-shapeups-shapeups-sleek-fit-c-50_75.html"><strong>Skecher Shape Ups</strong></a> walk to a large extent. This view wholesale <a href="http://www.shoeslockers.com/women-mbt-shoes-mbt-lami-shoes-c-49_61_67.html"><strong>Discount MBT Shoes</strong></a> a number of scientific ,Therefore, majestic mbt shoes and strengthen peoples understanding <a href="http://www.shoeslockers.com/skechers-shapeups-shape-ups-stability-c-50_74.html"><strong>shape ups Shoes</strong></a> .in <a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-tall-stripe-cable-c-53_101.html"><strong>shape up skechers</strong></a> through disseminate the majestic <a href="http://www.shoeslockers.com/ugg-boots-ugg-classic-tall-metallic-c-53_112.html"><strong>shape ups discount</strong></a> ideas and concepts.
Friday, October 15, 2010 8:51:32 AM (Romance Standard Time, UTC+01:00)
back pain and lumbosacral joint.Moreover, the girls who wear high heels early will lead to <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-casual-shoes-c-8_9.html"><strong>Discount Mbt Shoes</strong></a> the developing pelvic tilt, which make the <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-sandals-shoes-c-8_11.html"><strong>Mbt shoes clearance</strong></a>, is demanding.However, they are not only for people on their feet but for anyone who wants to wear a pair of comfortable <a href="http://www.zigtechshoesonsale.com/mbt-women-shoes-mbt-sports-shoes-c-15_26.html"><strong>Mbt shoes outlet</strong></a> that takes the pain away from your body when you are standing and walking. That’s why you need to wear <a href="http://www.zigtechshoesonsale.com/mbt-men-shoes-mbt-casual-shoes-c-8_9.html"><strong>MBT Sandals Shoes</strong></a>.
Monday, October 18, 2010 9:58:27 AM (Romance Standard Time, UTC+01:00)
I hope you have a nice day! Very good article, well written and very thought out. I am looking forward to reading more of your posts in the future.
haimingnatell
http://www.juicycouture4u.com/
Monday, October 18, 2010 9:59:13 AM (Romance Standard Time, UTC+01:00)
I hope you have a nice day! Very good article, well written and very thought out. I am looking forward to reading more of your posts in the future.
haimingnatell
http://www.juicycouture4u.com/
Thursday, November 04, 2010 4:58:11 AM (Romance Standard Time, UTC+01:00)
http://www.coachusabags.com/
http://www.asics-us.com/
http://www.ukuggus.com/
http://www.mbt-usa.com/
Friday, November 19, 2010 6:32:58 AM (Romance Standard Time, UTC+01:00)
I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading.Nice blog,I will keep visiting this blog very often.
Saturday, December 04, 2010 4:23:01 AM (Romance Standard Time, UTC+01:00)
this thing is worth to read. we enjoy it.
<a href="http://www.salemonclerstore.com/">discount moncler coats</a>
<a href="http://www.salemonclerstore.com/">cheap moncler vest</a>
<a href="http://www.designerbagsonsale.net/">designer handbags wholesale</a>
<a href="http://www.designerbagsonsale.net/">cheap designer handbags</a>
<a href="http://www.ghdchiirons.com/">ghd flat irons</a>
<a href="http://www.ghdchiirons.com/">discount ghd</a>
Saturday, December 04, 2010 4:23:14 AM (Romance Standard Time, UTC+01:00)
It sounds well for this paper.
<a href="http://www.ugg-classic-boots.us/">uggs classic short</a>
<a href="http://www.ugg-classic-boots.us/">uggs classic</a>
<a href="http://www.uggadirondackboot.com/">ugg adirondack</a>
<a href="http://www.uggadirondackboot.com/">ugg adirondack tall</a>
<a href="http://www.cheapuggbootstore.com/">cheap uggs</a>
<a href="http://www.cheapnorthfaceoutlet.com/">cheap north face jackets</a>
<a href="http://www.cheapnorthfaceoutlet.com/">north face outlet</a>
<a href="http://www.cheapnorthfaceoutlet.com/">north face sale</a>
Comments are closed.