Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Passive View and Web Client Software Factory – Easy Add View ( with Presenter ) Recipe

I love where Jeremy is going with his series of posts on Build Your Own CAB. I have to go back and read them all as I just caught the one this evening about the Passive View.


One of the monotonous things about the Passive View Pattern is that you need to constantly create a view, the interface it implements, and a presenter class. You also need to wire up the presenter and the view and have something somewhere automatically inject the dependencies.


Now this isn’t hard, but it sure is a pain as it adds overhead to the development process. One of the really nice things about the Web Client Software Factory ( and Smart Client ) is that you have these really nice Guidance Automation Toolkit Recipes that help you do all sorts of wonderful micro code generation during your development. One of them is the sweet Add View (with Presenter) Recipe shown below:


 


 Web Client Software Factory View Presenter Pattern


 


As I add the web page ( my view ), the recipe automatically creates the Presenter and Interface classes and adds the proper declarative code to signal the dependencies that need to be injected at runtime. During runtime, the Composition Web Application Block ( or CAB ) via ObjectBuilder will automatically inject these dependencies into the classes for me. Very, very cool! Saves me a heck of a lot of typing, wiring of classes, and the need to do my own dependency injection.


Where Jeremy is showing:


 

public ShippingScreenPresenter(IShippingScreen screen, IShipperRepository repository)
{
_screen = screen;
_repository
= repository;
}

 


The following question has got to cross your mind: Who the heck is injecting those screen and repository dependencies?


Well, with the Web Client Software Factory it is done automatically for you by re-writing it as such:


 

public ShippingScreenPresenter([ServiceDependency] IShipperRepository repository) : Presenter<IShippingScreen>
{
_repository = repository;
}

 


The View is automatically injected into the Presenter Class and so is the Repository. Huge time saver and some sweet loose coupling!


If Model-View-Presenter as well as Dependency Injection are new to you, the software factories are an excellent way to get up to speed on these proven practices as well as be more productive – at least until you can roll your own like Jeremy :)


by David Hayden

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

2 Responses to Passive View and Web Client Software Factory – Easy Add View ( with Presenter ) Recipe

  1. David Hayden says:

    Good point. I even modified and pulled out the GAT Recipes from the software factories and use them in my applications when I choose not to use the factories.

    The big assumption here, however, is that one has the skill and time to roll his own framework, which is not always the case.

    One of the pros about the software factories and application blocks is that they are supported and updated by Microsoft as proven practices and technology changes. This is nice as I don’t often get the chance to get familair with technologies quickly nor to the depth that the P&P Teams get to.

    A con to this, however, is that their development lifecycles are longer. Bugs don’t get fixed as quickly as I would like. The fact that we get the source code helps, but not everyone has the skill to modify the source code.

    In the end it has always been about picking the right tool for the right job and I don’t see this changing. These choices often go beyond the code-related issues and into the parts I hate to think about – time, support, extensibility, costs, available resources, etc., but this is the reality.

  2. Adam Dymitruk says:

    Roll your own enough times and you end up with some cool macros in VS and live templates in resharper…. faster than CAB in my experience

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>