Archive for July, 2009

Hello Open Rasta

So Ryan, the apostle of everything on the web, has been spreading the gospel of Open Rasta for months. Tonight I decided that finally, I should download and give this fantastical framework a shot.

For an explanation on what OpenRasta is and is not, I shall direct you to their sites:

  1. Open Rasta Documentation
  2. Open Rasta Download Home

What I am going to do is just describe my experience trying their framework for the first time.

I am a person that likes to learn by trying so I immediately jumped to the ‘creating your first OpenRasta website’ (here). I have looked at some of Ryan’s code and have survived several conversations with Ryan over the framework. ;) I believe that is enough preparation for at least a simple tutorial.

Well I go to the modifying the web.config section and was left with a broken solution. Apparently from the time the tutorial was written and the time I downloaded the version 2.0.2039.312, the handlers and modules all moved to another assembly. I had a gut feeling it moved and when I talked to Ryan, he confirmed my suspicions. Supposedly he is going to try and update the tutorial.

In the meantime, just change …."OpenRasta.Web.OpenRastaHandler, OpenRasta"

to… "OpenRasta.Hosting.AspNet.OpenRastaHandler, OpenRasta.Hosting.AspNet"

So change the assembly reference from the OpenRasta.dll to the OpenRasta.Hosting.AspNet.dll

I assume if you are reading this you have the skill set to modify said correction for the other references.

After that I breezed through the creation of the ‘Home’ resource and the ‘Home’ handler. No duh? Any programmer can make a couple of classes. :)

I’m at the configuration section and I have to say, I love the fluent interface. Anyone who has talked to me in the past 6 months knows I love the pattern. It instantly makes any framework extremely approachable.

The tutorial has you making a manual configuration. I tried to find an auto configuration just using some intellisense with no luck. I will investigate this further. If I was going to use OpenRasta I would definitely want a convention based solution. Even with a nice fluent interface, I really don’t want to manually create all my mappings by hand.

But there is something to be said for simply creating a mapping like :

ResourceSpace.Has
    .ResourcesOfType<Home>()
    .AtUri("/home")
    .HandledBy<HomeHandler>();


I ran the app expecting the 405 method error as the tutorial predicts.. and got an empty page. I was using FireFox, so I jumped over to IE and was then greeted by the 405 error. I assume FireFox is either handling the problem gracefully or I don’t have some settings setup to display these errors. /shrug

So then I created my ‘Get’ method on my HomeHandler. One of the things that did attract me to OpenRasta was the POCO handlers. I’ve grown to appreciate very clean code with some acceptable conventions. Just makes life easier. I can focus on the domain problem and not the intricacies of any given framework.

Most of this seemingly new re-invention of HTTP as ESB, REST, Atom.. etc is interesting in that its a reexamining of a technology we use all the time. I haven’t done web development in roughly 3 years. The majority of my experience is in smart client apps. That is just the way my career and projects played out for me. The websites I created were always very basic and probably crap if judged by web developer gurus.

Anyway.

We click links and magically we get a web page. We don’t really think much about it. Sort of like turning on a light switch or starting your car. We just expect things to work and don’t really worry about it. How many drivers can actually explain a combustion engine?

There is a lot going on in the background to make the web work. This new (new to me at least) area of development is leveraging the tech the way it was supposed to be used (if I am to believe the pioneers in this arena). A lot of this is a change of perspective. And with any change of perspective it can take awhile to make the transition.

After that side trip down my ramblings, we come back to me having a handler with a Get method. Now I have graduated to a 406 error (as expected by the tutorial).

I then created my view as the tutorial suggested. Now upon trying to fluently configure.. I ran into a snag. Again the tutorial is out dated (which is fine for an open source and still growing framework).

I had to add the “OpenRasta.Codecs.WebForms.dll” to the solution.

Also the fluent configuration suggested is…

ResourceSpace.Has.ResourcesOfType<Home>()
        .AtUri("/home")
        .HandledBy<HomeHandler>()
        .AndRendededByAspx("~/Views/HomeView.aspx");

But since the AndRendededByAspx is obselete, the code should now be:

ResourceSpace.Has.ResourcesOfType<Home>()
                    .AtUri("/home")
                    .HandledBy<HomeHandler>()
                    .RenderedByAspx("~/Views/HomeView.aspx");

I then continued the tutorial until I had my Home View that displayed my lovely welcome message.

Yay! I got my first Open Rasta page to work. :)

Feel free to investigate my project at my Git Hub repository:

http://github.com/RookieOne/OpenRastaExperiment/tree/TutorialCompletion

I’m going to be continuing to change the master branch but the TutorialCompletion branch should remain unchanged.

SO check out OpenRasta and their (and my) tutorial. Its short and is a great window into viewing the web in a slightly different manner.

Thanks for your time!

Model Validation

I got into an interesting conversation with my friend and coworker David Morton regarding model validation. Where does it belong? I have seen examples of self-validating models, validation as a service, and even UI-only validation.

Perhaps it depends on the implementation, but if you follow SOLID principles, I think you will at least end up with a validator type that performs the validation, either as a strategy on the model or a separate service.

We started with self-validating anemic domain models on my last project. That’s possibly an oversimplification, but it worked well for those models that were truly used in a CRUD-only manner. More complex models quickly became difficult to maintain, and as part of the refactoring, we split out the validation duties into their own class and now provide validation through the service layer for the client. This acts as a sort of anticorruption layer (Evans).

I really like this approach best. You can still call the validation from the client before sending, and your model may continue to focus on it’s real job. What are your thoughts or preferred approaches?

Looking for a new browser

Firefox 3.5 was recently released, and I’m now looking for a new browser. While the plugins are great and seem irreplaceable, the startup time has become atrocious and the memory usage is pretty bad. Most importantly, I haven’t been able to login to http://github.com/ using FF 3.5 at all, and I’m on there quite a bit these days. Not a winning combination.

First I tried Opera. It’s neat, but it’s just too different from what I’m used to, and so many of the extra features just don’t appeal to me. It did seem fast and everything, just not my cup of tea.

So then I tried out Safari. I like Safari 4 quite a lot. Two small quirks: you can’t opt to open to the last browser session automatically—a feature I fell in love with in FF—and the memory usage is worse than FF. It’s almost as bad as Visual Studio. (Both were running near or in the 300k mark.)

Enter Google Chrome. I tried it a few months back but wasn’t very impressed; at least not impressed enough to give up Firefox. With Firefox misbehaving so badly, though, I really feel I have no choice but to give Chrome a second look. And wow! Memory usage is very low, generally in the 30k range. It’s fast. Really fast. Firefox 3.5 says it’s fast, but I don’t think it has anything on Chrome.

So right now, I’m using Chrome. I like it. It continues to grow on me. But I’m curious, have any of you had this experience? What are your thoughts? What are you using?

I’m a REST Ninja

I was finally listening to Alan Dean’s talk on REST from the European VAN. In it, he stated that anyone who fully understands hypermedia is a REST ninja. Well, I understand it, though I’m not sure in the fullest extent that he perhaps means. Nevertheless, I’ll go ahead and claim it considering so few others seem to understand. At least I can help spread the message. More to come on that; I’m writing and working on some things to try to help others get it, too.

Be sure to check out the E-VAN talk by Jim Webber and Ian Robinson on July 20th. Most of what I know I’ve learned from them.