So it was Christmas eve and I was in my car driving down to
Canberra to spend Christmas with my family.
It's not an exciting drive by any means, so I needed something to
keep me entertained, and like any good nerd that is thinking about
coding.
And then an idea hit me, ASP.NET Web Forms MVP Contrib
Project!
But lets back up a second...
I've been using the Model-View-Presenter (MVP) pattern in
ASP.NET Web Forms development for quite a while now. I help roll
out a framework in Next Digital for all ASP.NET builds and I'll
admit it wasn't a bad framework.
A few months before I moved on I noticed a tweet from Damien Edwards (Victorian-based Microsoft MVP for
ASP.NET), stating that he was working on a MVP framework.
I immediately jumped at the idea, and had a look at the preview
build, and I was hooked. Easy to use framework, code re-use and
completely unit-testable ASP.NET Web Forms development? Why
not!
One of the initial problems was that you had to register
presenters at a page level, which wasn't possible from Umbraco
development, I submitted a patch to allow it, but it eventually
became redundant as the framework removed that limitation itself
(after I pestered Tatham Oddie).
So I've been constantly been trying to find ways in which I can
use or extend the framework. We've got a project already under way
at The FARM which is using it, but I wasn't content there, and here
is where the Contrib project comes in.
If you're not already familiar with ASP.NET Web Forms
MVP I suggest you have a read/ watch of the framework
documentation before you continue along.
What is the Contrib Project?
Since ASP.NET Web Forms MVP is little more than
a framework you still have to do a lot of stuff yourself, stuff
which you're going to probably do many times over, and this is what
the Contrib Project is aiming to help you with.
Currently the Contrib consists of a few common
presenters. They are presenters which represent functionality which
I seem to be constantly building myself. At the point of writing
the Contrib Project consists of the following presenters:
- Authentication
- News Archive
- News Article
- Google Analytics
- Feedback Form
These presenters can almost be used straight off the
bat, just the Authentication, News Archive and News Article all
require a Data Service to be provided (more on that shortly
though).
In addition to the presenters the following Views are
provided:
- IAuthenticationView
- INewsArchiveView
- IFeedbackView
These views are either for just wiring up events or providing
some view-implementation data (such as with the INewsArchiveView
interface).
But there are also a non-view interfaces provided which have some
default operations, these are:
- IValidatable
- ISubmittable`T
- ICancelable`T
These interfaces just provide some events or properties to a
view which can be used if and when they are required (in fact they
are used by some of the default views).
Data Services
As I mentioned above some of the presenters can't be directly
used because they require a Data Service. This is something which
we use at The FARM, which abstracts away the data interaction
layer.
Our data layer is exposed entirely as interfaces, and all
interactivity is done through predefined methods.
All data is also returned in interface form.
Shannon has done a blog post which covers this in some detail on
our company developer blog.
And going into the full details of how to use the Data Service as
a pattern is beyond the scope of this post.
Essentially it is about IoC, you need to provide a data service.
This is something that the framework can't provide for you.
To use these presenters you'll need to create an implementation of
them yourself which passes in the appropriate data service into the
presenter in the .ctor(IView view) call.
The provided data services are:
- IAuthenticationService
- INewsService
What now?
Now you should head over and check out the Contrib Project on Codeplex! I'll have an
official release coming soon, along with more documentation about
the presenters, views and data services.
And if you've got something you want to add to the Contrib
project drop me a message.