Screencast: Build an Asp.net MVC application quickly using MVCExtensions

by Tom 29. January 2010 20:16

Introduction

This is my first screencast for my MVCExtensions project, it shows you how to get started and build a simple tasklist.

PS: This is the direct link to the powerpoint used:
http://docs.google.com/present/view?id=dgt3mk3c_6fmhrd9c5

Some background info

This was my first screencast, and it took me about 7 attempts to finally get it to a point where it was more or less acceptable. For my sixth and seventh attempt I finally found some good screencap software : BBFlashback Express.

Anyway, this has been an interesting experience, and now enjoy mvcextensions !!!

More...

Tags: , , , , ,

CodeProject | Development | Howto | News

The advantage of using BDD over TDD

by Tom 26. January 2010 13:48

Introduction

After reading the latest post from @jeremydmiller I felt the urge to write a small article about the BDD part since there might be missing a vital part here about BDD...

More...

Tags: , , , , , , ,

CodeProject | Development | News

Build asp.net MVC applications FAST with MVCExtensions v0.4

by Tom 20. January 2010 19:28

Introduction

Today I finished v0.4 of my MVCExtensions library and I pushed the sourcecode to github.

I also included a very simple tasklist, in order to show you on how to get started using this library. You can also see (slightly outdated) example code in this blog post...

You can see a demo of the tasklist app running here. (Try entering a task without a name, or with a name that has more then 256 chars to see the custom strings in action).

You can download the full sourcecode here.

Update

I now made a screencast as well. it is available here.

More...

Tags: , , , , , , , , , , ,

CodeProject | Development | News

Teaser on my upcoming mvcextensions project release

by Tom 18. January 2010 15:51

Hi there,

I am going to give you a quick teaser on how to setup a full asp.net mvc application with database & all the rest using my soon-to-be-updated MVCExtensions library.

More...

Tags: , , , , , , , ,

CodeProject | Development | News

2009 retrospective: .Net technologies and lessons learned

by Tom 2. January 2010 03:02

my pride & joy

Introduction

 

In December 2008 I was doing my job as a freelance technical analyst for a big company. While it was a very interesting job in several ways, I felt that a burn-out was coming up. I had no idea whether this was due to the job, or due to my personal merits ( a newborn and a one-year old son, lots of tasks and chores on my to-do list for our house, a busy social life, ...) Instead of waiting for the man with the hammer, I decided to be proactive about it, so I decided to quit the job and reinvent myself during 2009.

It has been both an interesting, very challenging and enriching year for me, with both high peaks and low valleys.

I decided to write this blog post in order to evaluate myself, and I am hoping that other people might find some inspiration in this as well.

 

 

 

 

 

More...

Howto+why using a prototype & bdd for a project estimate + personal rant

by Tom 22. December 2009 13:57

Introduction

As you might or might not now, estimating the budget for a project can be very hard sometimes. In order to get started on a project we first need a real estimate of what the client will need, and the client should know what I am going to deliver to him/her.
What I personally learned from the past is that one can never be fine-grained enough, since there will always be mismatches somewhere.

We can however try to offer the client something that he/she can both understand and work with, next to a description of what everything should do (from a business point of view).

How can we do this, while investing as little work as possible ?

 

Unfortunately one can not correctly estimate projects without doing some work

As straightforward as this might seem, most people do not seem to be able to grasp this ( do not be ashamed; I have been guilty as well ).

In order to give a correct estimate, you have to INVEST a decent amount of TIME.

More...

Tags: , , , , ,

CodeProject | Development | Howto | News | Tom's blog

The Quest for the perfect ASP.Net MVC code : v0.3

by Tom 7. December 2009 20:26

You can download the full source here using (msys)git:
     http://github.com/ToJans/MVCExtensions


// The quest for perfect asp.net MVC code - v0.3
//
// For a while I have been looking for the perfect ASP.Net MVC code.
// This is the cleanest code I have been able to write.
// I would like to challenge everyone to do better !!!
//
// By this I mean creating a better controller/views if possible codewise.
// The focus is not on the layout stuff, but having it might be a plus.
//
// The scope : a very rudimentary Task list (KISS)
//
// You can download the full source here using (msys)git:
//     http://github.com/ToJans/MVCExtensions
//
// You will see it is very easy to alter, just fetch it with git and press F5
//
// Please do let me know what you think about my approach as well,
// and whether you could do better: ToJans@twitter
// Send this link to as much fellow coders as possible, so we can see lots of alternatives
//
// PS: you can also leave a comment @ my website (look at my twitter account for the url)
//
// Edit: this is my third version, and I am still looking for improvements
//
// Some noteworthy facts :
// - In the MVCapp, there only DLL directly referenced is the ViewModel DLL,
//   so the views do NOT reference the controllers anywhere
// - The controller contains only logic & domain model objects => VERY CLEAN Controller
// - The resulting controller action model is mapped to the ViewModel using
//   IMapper.Map<source,ViewModel>(s,vm)
// - The viewmodel should include everything that should be visible on the screen, so not only
//   data but also the actionlinks one can use
// - The actionlinks for the viewpages are defined in the IMapper, and automaticly passed on to
//   the view => you can see/alter the program flow in the mapping definitions
// - Stubbing the controller should be a piece of cake using this code, so you could use this
//   design to easily develop application mockups that are ready to be implemented once the client
//   approves, so first build your viewmodels and views, show it to the client, and upon agreement
//   start development on the controller.... In fact I am going to test this method on my next project
//
// Kind regards,
// Tom Janssens

More...

Tags: , , ,

CodeProject | Development | News | Tom's blog

The Quest for the perfect ASP.Net MVC code : Let the games begin

by Tom 3. December 2009 19:41

Edit:

Please note that the source has changed a lot lately, and that I now use a proper viewmodel instead of domain objects, so all hardlinked references to the domain objects & controllers in the MVC project have disappeared. This also automaticly made my ugly domain object extension methods to get the controller action links completely redundant.

You can see the latest version on github.

The next thing to do is split up the mapping bit using a proper mapping tool (f.e. AutoMapper).

Edit 2:

New article here : The Quest for the perfect ASP.Net MVC code : v0.3

// For a while I have been looking for the perfect ASP.Net MVC code.
// This is the cleanest code I have been able to write.
// I would like to challenge everyone to do better !!!
//
// By this I mean creating a better controller/views if possible codewise.
// The focus is not on the layout stuff, but having it might be a plus.
//
// The scope : a very rudimentary Task list (KISS)
//
// Some more info about my approach :
// It uses view models which contain both data and ActionLink references
// (like ICommand in WPF M-V-VM )
//
// You can download the full source here :
//     http://github.com/ToJans/MVCExtensions/tree/master/src/
//
// You will see it is very easy to alter, just download it and press F5
//
// Please do let me know what you think about my approach as well,
// and whether you could do better: ToJans@twitter
// Send this link to as much fellow coders as possible, so we can see lots of alternatives
//
// PS: you can also leave a comment @ my website (look at my twitter account)
//

// --------------------------------------------------------------------------------
// Controller :
// --------------------------------------------------------------------------------
namespace Tasks.Core.Controllers
{
    public class TaskController : Controller
    {
        // for the sake of the demo we do not use DI
        // but just a static class instance here with a fake repo
        static IRepository<Task> rTask = rTask ?? new FakeRepository<Task>(null);

        public ActionResult Index()
        {
            return View(new VMIndex()
            {
                AllTasks = rTask.Find.OrderBy(o => o.Name),
                AL_AddTask = this.ActionLink("Add new task",c=>c.AddNewTask(null,null))
            });
        }

        public ActionResult AddNewTask(string name,string description)
        {
            var t = new Task() { Description = description, Name = name };
            rTask.SaveOrUpdate(t);
            return this.RedirectToAction(c => c.Index());
        }

        public ActionResult Done(int id)
        {
            var t = rTask.GetById(id);
            t.Done = !t.Done;
            rTask.SaveOrUpdate(t);
            return this.RedirectToAction(c=>c.Index());
        }

        public ActionResult Edit(int id)
        {
            var t = rTask.GetById(id);
            return View(new VMEdit()
            {
                 Name = t.Name,
                 Description = t.Description,
                 AL_PostEdit = this.ActionLink("Save changes",c=>c.PostEdit(t.Id,null,null)),
                 AL_CancelEdit = this.ActionLink("Cancel changes",c=>c.Index())
            });
        }

        public ActionResult PostEdit(int id,string name,string description)
        {
            var t = rTask.GetById(id);
            t.Name = name;
            t.Description = description;
            rTask.SaveOrUpdate(t);
            return this.RedirectToAction(c => c.Index());
        }

        public ActionResult Delete(int id)
        {
            rTask.Delete(rTask.GetById(id));
            return this.RedirectToAction(c => c.Index());
        }
    }
}

// --------------------------------------------------------------------------------
// Index.Spark
// --------------------------------------------------------------------------------
<viewdata model="Tasks.Core.ViewModel.Tasks.VMIndex" />
<content name="Title">
    Index
</content>

<content name="Main">
<h1>Task list</h1>
<if condition="Model.AllTasks.Count()==0">
    No tasks yet.
</if>
<else>
  <table>
    <tr>
      <td>Name</td>
      <td>Name</td>
      <td>Status</td>
      <td>Edit</td>
      <td>Delete</td>
    </tr>
    <tr each="var t in Model.AllTasks">
        <td>${t.Name}</td>
        <td>${t.Description}</td>
        <td><alink a="t.AL_Status()" /></td>
        <td><alink a="t.AL_Edit()" /> </td>
        <td><alink a="t.AL_Delete()" /> </td>
    </tr>
  </table>
</else>
<hr />
<h3>Add a new task</h3>
    <aform a="Model.AL_AddTask">
      <label for="Name">Name :</label><br />
      <input type="text" name="Name" /><br />
      <label for="Description">Description:</label><br />
      <textarea cols="20" rows="2" name="Description" ></textarea><br />
    </aform>
</content>

// --------------------------------------------------------------------------------
// Edit.Spark
// --------------------------------------------------------------------------------
<viewdata model="Tasks.Core.ViewModel.Tasks.VMEdit" />

<content name="Title">
    Edit
</content>
<content name="Main">
        <h3>Edit this task</h3>
        <aform a="Model.AL_PostEdit">
            <label for="Name">Name :</label><br/>
            <input type="text" value="${Model.Name}" name="Name" /><br/>
            <label for="Description">Description:</label><br/>
            <textarea cols="20" rows="2" name="Description" >${Model.Description}</textarea><br />
        </aform>
        <alink a="Model.AL_CancelEdit" />
</content>

 

 

Bookmark and Share

Tags: , , ,

CodeProject | Development | News | Tom's blog

Rant : Your abomination is my clever hack

by Tom 2. December 2009 03:55

When I read the article from OdeToCode about the abuse of a programming language to create shortcuts, I felt the need to respond.

What is it about ?

Simply stated, it is about using some clever tricks to make it easier for the developer to reach his goal. The example was a stackoverflow post : Abuse of C# lambda expressions or Syntax brilliance?

Which discusses code that looks like this :

.Attributes(style => "width:100%")

What is the issue here ?

The issue was that the reaction of the c# language designers. They said it was unacceptable to use such a shortcut, since it was not originally intended in the language design. According to them, one should never use such a construct. I firmly disagree...

Why should one be allowed to abuse a development language ?

Simply stated : because you can. Every single thing that can help a developer to make cleaner/safer/better code (in his/her opinion) should be allowed. Why do we develop most of our applications in c#/java/ruby/PHP and not in assembly ? Because using these languages is considered cleaner/safer/better then using assembly. So while the original language designers might not like the idea, the hacks provide an extra cleaner/safer/better way to address a certain implementation subdomain. After all, the language is there as an intermediate between the developer and the hardware, and anything that allows better communication between the developer and the hardware, should be considered a plus... Which brings us to our next point of attention.

Who is saying that the approach you use here is cleaner/safer/better ?

Actually : nobody. That is something that you need to find out yourself. While some people might like to use the shown constuct, others might like the more verbose way of expressing things. Most of the time, these shortcuts are there as an alternative to the "common" way to do something. In most cases, the fact whether you like or dislike something is based on your background/knowledge/reference frame .
The fact that the alternative was built means that somebody had the intention of providing a better/safer/cleaner way of doing something. Whether you agree or disagree with this person is completely up to you... (Although I must admit that I certainly agree with this person). If you look at the dynamicobject feature (another heavy point of discussion), then you might see that this actually does something simular as the shortcut used here, so the language development team is actually doing the same.

Please note that it does not stop here; some people found the original c#/vb.net language to constraining, so they developed their own, including a manifest.

So, to conclude, if you think you can make your own life easier by using certain 'abusive' constructs : please do !!!

Bookmark and Share

Tags: , ,

CodeProject | Development | News | Tom's blog

M-V-VM in Asp.Net MVC : removing dependencies between asp.Net views and controller actions

by Tom 30. November 2009 06:32

Since the early days I have always been a fan of the ASP.net MVC framework, although I had one really big issue with it : the coupling of the controller actions in the view pages. This part was a real annoyance, since all the flow and logic was included in the controller, and none of it in the views, _except_ the action flow; this was included in the views by using Html.ActionLink.

This has always been a nuisance for me, so last week, as I was working on a project, I decided to fix this issue...

IMHO the possible proceeding controller actions in the program flow should be defined in the controller action, and not in the view. So how could we do this, while still making it maintainable and easy to follow ?

After considering a few alternative routes, and thinking about it event more, it suddenly hit me; why not represent the possible routes as data.

A few development cycles later I had the following code in the controller:


public ActionResult Index()
{
     ViewData.Model = new VMIndex()
     {
         AllTasks = rTask.Find.OrderBy(o => o.Name),
         AL_AddTask = this.ActionLink("Add new task",c=>c.AddNewTask(null,null))
     };
     return View();
}

And this code in the view :


<h1>Task list</h1>
<%= Html.Grid(Model.AllTasks)
        .Columns(c=> {
            c.For(t => t.Name);
            c.For(t => t.Description);
            c.For(t => Html.ActionLink(t.AL_Status())).Named("Status").DoNotEncode();
            c.For(t => Html.ActionLink(t.AL_Edit())).Named("Edit").DoNotEncode();
            c.For(t => Html.ActionLink(t.AL_Delete())).Named("Delete").DoNotEncode();
        }).Empty("No tasks yet")
%>
<hr />
<h3>Add a new task</h3>
<% using (Html.BeginForm(Model.AL_AddTask)) { %>
    Name<br />
    <%=Html.TextBox("Name") %><br />
    Description<br />
    <%=Html.TextArea("Description") %><br />
    <%=Html.SubmitButton(Model.AL_AddTask) %><br />
<% }%>

Which looks rather nice in my opinion. Since I do not know whether I am the first person who thinks about this or not, I decided to publish the sourcecode together with an example on github.

The technical implementation is actually quite simple; I implement the Model-View-Viewmodel pattern, which is used in WPF, using a simple wrapper class for the action links (i.e. commands in MVVM). Once I made that link, the rest was childs play.

Next to this I also created some helper extensions, to make the code a little easier on the eyes.

I also think that by using this pattern we should be able to implement a winforms/WPF app using the same controller. Anybody who is willing to send me a git patch of a WPF application using this controller: please do !!!

PS: This also makes the actionlinks testable in an easy way; another responsibility that has been taken away from the view !!!

Bookmark and Share

Tags: , , , , ,

CodeProject | Development | News | Tom's blog

About me

Tom Janssens op LinkedIn

Tom Janssens op twitter

Core bvba RSS

My name is Tom Janssens and I am the owner of Core bvba, a software and consultancy company.
I am married to Liesbeth and have 2 sons named Quinten and Matisse.
ICT is both my job and passion.
Next to this my other hobby is actively playing music (mostly guitar).

More info about me and my company...

Recent Comments

Comment RSS