So, I just installed the new ASP.NET MVC release (see Scott Gu's blog) and updated my project which was based on beta 1. In the release notes there were some information about how to upgrade, although I somehow managed to screw it up so I got "HtmlHelper does not contain RenderPartial" error messages. The issue I had was that I messed up the namespaces in the web.config. To see how it should be just create a new ASP.NET MVC project and compare the web.config with your current web.config.

There has been a change to the ModelBinder API which produced compilation errors, the ModelBinderResult class seems to have been removed and the BindModel() method now takes two arguments of type: ControllerContext and ModelBindingContext. The ControllerContext contains among other things the HttpContext. The BindModel() method doesn't remove the ModelBinderResult anymore, instead it returns object. That change seems a bit weird, but I'm sure it was done with a lot of consideration.

There was another breaking change for me which had to do with the ModelStateDictionary. The method SetAttemptedValue(string key, string value) is removed? I'm not sure if it's been replaced by the method SetModelValue(string key, ValueProviderResult result), I can't find any information about it in the release notes.

What I did find in the release notes however was the improved support for file upload, just in time for me to begin implementation of a an upload document and image feature for the web application I'm currently building.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

poeaa

Last night I finished the book Patterns of Enterprise Application Architecture by Martin Fowler. It's been sitting on my pile of shame for some time and I finally got around to reading it, which I'm very glad for. The layout of the chapters is similar to Martin Fowlers "other" book Refactoring: Improving the design of existing code. The book is divided into two parts. The first part contains general information about layering, structuring domain logic and "putting it all together" information. The second part contains detailed description with examples about enterprise patterns. I enjoyed the first part of the book the most. I consider the second part more or less like a reference, I'll use it to look up a pattern whenever I need to.

Any developer could benefit from reading the book, no matter which language your primary programming language is. The examples in the book are written in Java and C# and are easy to follow. There's also a good pro vs con description in the first part of the book telling you the advantage and disadvantages of each pattern. I highly recommend this book.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Domain-Driven Design (DDD)

Posted on December 16 by bjn
51sbuQIxz9L._SL500_AA240_

Last week I attended the course "Implementing Domain-Driven Design using LINQ" with Jimmy Nilsson in Stockholm. As you know Jimmy is the author of "Applying Domain-Driven Design and Patterns". This was the first time I really got acquainted with DDD and what better way than being introduced by Jimmy Nilsson?

I must say I really enjoyed the course, first of all there were only six of us that attended the course which led to really good discussions and there were a lot of time to ask questions. Second, I've been to a few presentations that Jimmy has done and I've never been disappointed. You can tell that he has done quite a few presentations by the way he acts. He's calm and he always has some way to make things easier to understand.

It was only a 2-days course so we only had the chance to cover the bare minimum of DDD, however, I feel like I've been thinking more and more with a DDD mindset after the course. By inspecting one of my projects a bit closer I discovered that the domain layer was pretty close to DDD already. In the project there is a few service classes which would be repositories in DDD. For example, there is a MemberService with two methods: FindByUsernameAndPassword and FindByEmail. There is however some work that has to be done to sort out all classes and categorize them into Entities and Value objects.

I'm hoping to be able to try out some DDD in an upcoming project. Until then I'll read Jimmys book and Eric Evans "Domain-Driven Design: Tackling Complexity in the Heart of Software".

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

This blog is hosted by Surftown which is a cheap and pretty decent shared web host. I've been looking for some sort of CMS to do simple web sites, I've had requests from a few of my friends if I could help them set up a web site. Sure, no problem. However, I'm looking for something that could be sort of a framework I could build all these sites on, which I could customize to fit my needs. I started looking at Umbraco (www.umbraco.org) which looks really good, but unfortunately does not work with medium trust. Found Cuyahoga(http://www.cuyahoga-project.org/) which also was very promising but with the same problem, no support under medium trust...

With the simple requirements I have it's more or less no point to look and evaluate another CMS, I could just as easily build one myself. While building it I could use some ASP.NET MVC which I really enjoy and hope to dig into a bit more. But, a few questions remained. Does Surftown support .NET 3.5? Does ASP.NET MVC need full trust? I was pretty sure ASP.NET MVC didn't need full trust to operate. But would it work on Surftown?

I created the sample project in Visual Studio 2008 and published my site to a subdomain to see if it worked. The first I received was the 404 not found when browsing /Home. Fair enough, changed the route to be /Home.aspx instead. It looks like ASP.NET but atleast you'll know it's not the traditional ASP.NET. Voilá, it worked. Best news I've had all day, now to do a simple CMS... how hard could it be?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Michael Feathers is interviewed by Carl and Richard in show #397, Michael Feathers is the author of the book Working Effectively with Legacy Code. I've started doing a review of his book and the interview with Michael on .NET Rocks! will get me going with his book again for sure, unfortunately I've been busy reading other books but I hope to finish Working Effectively With Legacy Code soon.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Today I had an epiphany of how powerful PowerShell is. I was using a dependency visualizer named Dependency Visualizer (http://www.codeplex.com/dependencyvisualizer) to try to get a quick overview of how the projects were related in a fairly large system. The problem was that if I used the Dependency Visualizer on the solution file, which contains close to 150 projects I would get a rather nasty overview. What I wanted to do was to execute the Dependency Visualizer on each project file in the directory any sub-directory within it. To do that I realized I could probably use PowerShell. Off I went to install it and 5 minutes later I had the following:

> dir -recurse -filter *.csproj | % { &"c:\program files\dependency visualizer\dependencyvisualizer.exe" $_.FullName}

Which for each file with the extension csproj within this directory and any sub-directory execute the dependencyvisualizer.exe with the full name as an argument. This produced an svg image for each project file on my file system. Extremely powerful!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

BlogView 1.0.1 released

Posted on October 19 by bjn

New release of BlogView, with no new functionality, only recompiled it targeting .NET 2.0 and changed the HostApplication Version to 8.0 instead of 9.0. It now works with both Visual Studio 2005 and 2008.

I also changed the installation, not using LINQ to xml for updating the Assembly path to the add-in.

Download BlogView 1.0.1 (Visual Studio 2005/2008)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

After installing Visual Studio 2008 SP1 I started to get weird crashes while trying to view aspx markup in ASP.NET MVC Preview 5 projects. The IDE would just disappear without any error messages. I tried rebooting my machine, but it didn't help. I looked in the event log and found this message:

.NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (6EF35E00) (80131506)

Not very informative but at least something use when searching the web. I found a few posts with this error message, some posts had tips on how they solved the issue. I tried to clearing out my temp folders

  • c:\windows\temp
  • c:\users\<user>\appdata\local\temp
  • c:\windows\microsoft.net\framework\v2\temporary internet files

Unfortunately that didn't resolve the issue, Visual Studio continued to crash.

Since I had installed the Silverlight 2.0 Tools and SDK recently I figured it might be cause of the problem. Uninstalled it and rebooted the machine but to no avail. I started to look through the programs I had installed, trying to find anyone that could cause the problems. Among a few tools I've installed were PowerCommands for Visual Studio 2008. Uninstalling it solved the issue. Very weird, I hope it gets fixed soon. PowerCommands is great and I hope to be able to install it soon again.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Following the Evaluating a move from Monorail over to ASP.NET MVC post, I started to dig deeper into the authorization mechanism in ASP.NET MVC. There were some core differences, in ASP.NET MVC they had taken a step further with authorization and created a specific filter Authorize implementing the IAuthorizationFilter interface. This enables you to specify users and roles that are authorized to invoke a certain action on a controller. For example if you require that only users in the "Administrators" role are allowed to invoke Index() it would like this:

Authorization filter in ASP.NET MVC

Where you decorate the controller with a special [Authorize(Roles="Administrators")] filter attribute. This [Authorize] filter would check the user before invoking the Index() method. If the user did not had the specific role it would output an error. If the user is not logged in it would be redirected to the login page etc.

This is very nice, you can do the same in Monorail since filters exists in both ASP.NET MVC and Monorail. However, in Monorail you had to specify that the filter would be executed before the action is invoked and there is no special treatment for the filter. It's treated just like any other filter. In my application it looks like this (the selected line):

Authorization filter in Monorail

You explicitly has to specify that the filter should be executed before the action, it wouldn't make much sense otherwise for an authorization filter, if it would be invoked after the action has been executed. To make sure that you don't miss this they specifically created an interface IAuthorizationFilter which always will be executed before any action. Personally I really like this approach, this way you won't accidentally forget to specify it should be executed before any action.

So far so good, in ASP.NET MVC there's no need to explicitly specify it should be executed before and there's no question about what the filter does, just read the name of the filter. Unfortunately, since the Authorize filter in ASP.NET MVC only works with users and roles I either has to change my Monorail authorization and permission scheme or implement a new feature in ASP.NET MVC. In my application I do not specify Users or Roles in the application, instead I use permissions after a suggestion from Christer. I must say it's been great, the system feels a lot more flexible when I can define different permissions. For example my job advertisement controller has five actions: Create, Update, Delete, Read and Approve. Which gets translated into five different permissions CreateAdvertisement, UpdateAdvertisement, DeleteAdvertisement, ReadAdvertisement and ApproveAdvertisement. The actions on the controller are decorated with the suitable permission. This way I can manage the permissions so that any user can read advertisements. Any logged in user can create and update their own job advertisement. Only administrators can approve new job advertisements and delete existing advertisements. In the administration view it's possible to change these permissions.

permissions3

Of course, this can be done using roles only. Hard coding in roles into the application. But this way, there's another layer of abstraction which hopefully doesn't need to change after all permissions are specified. Another advantage using this permission approach is that whenever you need to add another role to the system you only need to specify it and then go into the administrations view and determine which rights the role should have. No need to browse through each action for each controller in the system, and hoping that you didn't miss any.

Fortunately, the team behind ASP.NET MVC has made it super easy to just create a new authorization filter. All you need to do is create a class that implements the IAuthorizationFilter and inherits from the FilterAttribute class (actually, I'm not sure it needs to be derived from the FilterAttribute class). For example I created the RequirePermission attribute, which implements the IAuthorizationFilter. The only method in IAuthorizationFilter is the void OnAuthorization(AuthorizationContext filterContext). After that I could decorate my Delete() method with the new AuthorizationFilter: RequirePermission.

permission4

Which would enable the system to verify the role of the user against the relation between role and permission.

I must say that ASP.NET MVC has made some progress regarding authorization, comparing to Monorail. They are almost implemented identically, however there are some subtle differences that makes a huge difference in my opinion. It's impressive how easy it is to implement new filters in ASP.NET MVC.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

I started building a web site for my father a few years ago, back then I based it on PHP/MySQL. After some time I discovered Ruby on Rails and rebuilt most of the system using RoR, although I didn't complete the project for a few reasons (not going into detail here). Late 2007 I started to thinking about rebuilding it and leaned toward using .NET. I was thinking I could use it to try out some new technologies in .NET that I hadn't used yet. I'm not a big fan of ASP.NET, so using traditional ASP.NET was out of the question. Since I'm used to PHP and using POST/GET and reading query strings etc I feel that ASP.NET actually confuses developers with postbacks, events and viewstates causing all sorts of problems. Another issue of ASP.NET is the testability, it's cumbersome to write unit tests for ASP.NET applications, it's possible for example using a Model-View-Presenter (MVP) pattern.

Looking for another web framework to use I found Monorail, which is a MVC framework by Castle Project inspired by ActionPack. It's built on top of ASP.NET but, everything gets routed to an action on a controller. I also discovered ASP.NET MVC, however, it was so early that it felt like it changed a lot between every preview, big breaking changes which would meant fixing a lot of code whenever upgrading to a newer preview. That's way I settled with Monorail for the time being.

The web application that was built had the following features

  • Membership (Users, groups and permissions)
  • CMS (pages and menus)
  • Questionnaire
  • Create conference and have members registering to attend
  • Create, send as PDF and manage invoices (the sum of the invoices for the last conference was close to $350 000)
  • Post job advertisements
  • Forum

The web framework used was Monorail and for data access I used NHibernate with ActiveRecord, which made my life so much easier. It's incredible powerful to be able to re-create the database with just a command and be able to switch between different databases by only changing the configuration. At one time I developed the application on my development machine which had a SQL 2005 server and I deployed to a MySQL server and it worked right out of the box. I used the ability to destroy and create the database a lot when creating integration tests. No need to try to reset the database to a specific state, now I was confident that everything was exactly the same each time I ran the tests. The database got swiped and created between each test. There's also the possibility to use an in memory database such as SQLite for performing integration tests, since it only resides in memory it's incredible fast.

I'm pretty pleased with the outcome of the system, it's working great and it's easy to add new features. But, I'm like many of you, I always want to try new things and learn more. Now when ASP.NET MVC has had almost a full year of development since I last visited it I feel like it's time for doing another re-build of the system. This time I'm hoping to be able to re-use some of the business logic and a lot of the data access layer since I'm still going to use NHibernate. I know Entity Framework (EF) has been released, but it's lacking a lot of features and is at the moment inferior to NHibernate. I'm sure it will turn out great when version 2 is released of EF, and I'll probably replace the data access layer when it's out :)

Looking through the code for the web application today trying to look for what needs to be replaced when moving over to ASP.NET MVC from Monorail, it feels like it's not really that much that needs to be changed. I could use a NVelocity view engine keeping the views more or less intact. The data layer is the same and since I wrapped everything in services the controller does not really contain a lot of logic, it'll certainly help. However, obviously there are some core differences between Monorail and ASP.NET MVC. I'm going to go over the issues I encounter one by one as I browse through the code looking for certain perks that needs to either be rewritten in ASP.NET MVC or could just be moved over simply by renaming some classes etc. I'm really looking forward to try out the new features in ASP.NET MVC that I haven't looked at yet, particularly that controller action is not void anymore, instead they return an object. This will make unit testing so much easier.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5