ObjectContainerDataSource and non-ASP.NET platforms? RRS feed

  • Question

  • Hi all,

    We are starting a project that will have alot of logic that will be used by both an ASP.NET UI and a WinForms UI. Alot of the forms in both UIs will implement the same layout and functionality. I am looking at implementing the MVP pattern as this seems to be the best choice for the way we develop and for ensuring that we can cut down on reproducing logic for the different UIs. In my investigations I have come across large hurdles in implementing complex data UI controls such as the ASP.NET ListView and the WinForms DataGridView while using the MVP pattern. The web client software factory provides the ObjectContainerDataSource to get around some of the problems that I have encountered, but is there anything similar for other platforms, such as WPF or WinForms? Or am I missing something here?

    Any advice you have to offer is greatly appreciated!

    Thank you,

    Wednesday, October 28, 2009 8:21 PM

All replies

  • Man - I really hate to be Debbie Downer but I have two points to share with you.  One, don't use the MVP pattern if you can get away with it.  You end up writing a lot of plumbing code!  I know...I wrote a whole book that relied on the MVP pattern.  It is not a bad pattern - don't get me wrong.  But when looking at the .NET MVC pattern (or MVC by itself) it is just so clear that MVC is so much better.  To have control over what is shown to the user prior to showing it to them is very powerful.  But what about winforms?  That is easy too.  Create your winforms apps with navigation or routing in mind.  Delegate the navigational control of your buttons and various other actions through a navigational controller.  There is a pattern out there for this that is escaping me at the moment...but you get the same power.  Someone is on a form...doing their thing...something with their account changes in the background...they click a button to move on to some other thing...the account change is intercepted...and they are redirected to a form to handle what ever.  While you could do this in the MVP pattern ...it is not the same.  Something that sits above the logic in your forms should be in control at all times no matter what.

    Regarding ObjectDataSource (LINQ DataSource...or any other)...don't use them!  To me this screams that you are using something like a gridview or listview or some other luxury control!  If at all possible steer clear of those.  There really is nothing wrong with using a for loop to spit out the contents of a collection of data.  You can even put it into your own control.  The reason I say this is that these controls are super heavy and do not provide you with 100% control over your code.  You get a control with one or two features that you need and 100 features that you don't.  Optimize for your needs.  I am not saying that you should create everything in house...but you should control the little things!  This will then allow you to design an architecture around what your application needs isntead of worrying about designing an architecture that covers what you need as well as what some 3rd party control requires!

    Try to put your design emphasis on following appropriate patterns (http://stackoverflow.com/questions/1637582/what-design-pattern-do-you-use-the-most/1639656#1639656 ).  This will make for flexible code that can grow with you.

    Since you are saying that you want two different clients (presentation) for the same backend code I do suggest that you try to decouple your presentation from your business layer as much as possible.  You might find an article series that I am writing to be of interest.  It walks the reader through how to create a simple ASP.NET MVC application (page to db direct via LINQ to SQL) and then takes you through a series of refactorings to get to a point where your application is as uncoupled and as abstracted as possible to create a distributable nTier style application.  The final result is many presenation tiers, some direct to BLL and some through WCF to BLL with a BLL that can have segments distributed to different servers with a pluggable DAL.  Quite fun!  Walks through ASP.NET MVC, LINQ to SQL, Domain Driven Design, WCF, Repository, StructureMap, Inverson of Control, TDD...etc.  Find these articles here under the Three Tiers to MVC section: http://dotnetslackers.com/projects/StackOverflowInspiredKnowledgeExchange/

    Let me know if you have any questions!

    Andrew Siemer www.andrewsiemer.com blog.andrewsiemer.com www.socialnetworkingin.net
    • Edited by Andrew Siemer Wednesday, October 28, 2009 9:00 PM Made the links links since that is not automatically done!
    Wednesday, October 28, 2009 8:58 PM
  • Hi,

    Just to add to Andrew's observations, the only place I havefound MVP to add a lot of value is when I have to do UI Testing independent of my BL. If your project is not too keen on UI testing then go with MVC.
    Thursday, October 29, 2009 2:53 AM
  • Hi guys,

    Thanks for your responses.  We will be UI testing, technocrat.

    Andrew, extactly what do you mean by plumbing code? From what I have seen in my investigations there is not much difference in terms of effort between implementing MVP or MVC. In fact, with MVC will we not have to implement the controllers twice (for WinForms and for ASP.NET)? I figured MVP would be better for cross platform development as the Presenter logic can be used for both platforms due it being completely decoupled from the UI by its very nature.

    As for implementing ASP.NET MVC, this is just not going to fit with us. We have years of experience in developing with WebForms and should continue to do so. The features and code-UI separation that are offered by the controlls are almost invaluable, especially as some of the forms we will be developing will be very complex. You can get more than enough control over their output with a small amount of work (overriding and browsers). Besides that, I have been following the developments within the MVC project and it just isn't something I would be happy to encourage our developers to use. I am not going to go back to using inline code within the HTML. We have learned our lessons from back in the day of classic ASP and PHP. Its a nightmare for our designers and it gets FAR too messy far too quickly for complex data entry forms that I'm almost tempted to shout at any of my colleagues who start to do such things.

    Anyways, back to the original question, it was not about the ObjectDataSource, rather the ObjectContainerDataSource control that has been developed to allow binding to complex data controls (i.e. WinForm's DataGridView, or ASP.NET's FormView) while using MVP. I was wondering if there is a similar control that we could use in WinForms development or, even better, if there is a more generic means of implementing this accross platforms. I think I'm probably just going to have to keep playing with this as I'm not sure I understand the logic behind it.


    Thursday, October 29, 2009 3:38 PM