CompositeWPF and WinForms

March 14th, 2009

We recently started a project for an LOB that acts as a very specific ERP. The requirements were simple, build a system in .NET, that contains all functionality of an old system and make it robust and extensible. Well, looking at the list of roughly 200 use cases we needed to cover, and taking into account it needed to be a WinForms application, I immediately started to be afraid of building a monolithic, Visual Studio Designer generated app.

I wanted to use concepts like modularization, avoiding coupling as much as possible, making clear dependencies and also teaching new and better development practices. I wanted to use some kind of composition framework.

The old Composite Application Block  seemed a bit rusty, the concepts a bit tricky to understand, and even harder to explain to a team of developers. So, I started looking into fresher libraries, with better conceptualization. I found and finally decided to use the newer Composite Application Guidance for WPF and Silverlight.

But hey, how can you use this with WinForms?

Well, it’s possible. Composite WPF library is extensible and even though it gives an implementation, nobody stops you in replacing components with your own or using only parts of it. Thanks to Brian Noyes and his nice post on Composite Extensions for Windows Forms the starting point was clear and made things seem possible.

Helped by a few enthusiats at work, we rolled out our sleves and put down a set of classes that implement the concepts of CompositeWpf, but this time using the Windows Forms “windows”.

We had to implement from scratch or adapt concepts like ClickCommandBehavior, Region, RegionManager.

Still, the toughest process was to support the Model-View-Presenter pattern. So, we decided that all our Views will implement an IView interface, that any IView can be hosted in a Region. But hey, how do you activate a View (which in our case are User Controls) in a Region? Well, our solution was to build a set of Host controls. For example, activating a View in a Dialog Region (Modal), is as easy as creating a Form and adding the View inside it. Of course, plumbing and hooking some events is needed, but for the developer, the feeling is the same as for the Composite WPF code, you just Activate a View in a Region.

Another tough part was to support UI Composition in Windows Forms. Imagine you have a Person, a Company and they each have an Address. Now, you want to include the Address View (edit or read only mode) in both screens for editing a Person and a Company. Well, this seems good practice: we promote re-usability, we have less code to hunt for bugs, we get consistency and so on. But how to do it in WinForms? Well, since our Views are User Controls, we can nest them, but how? Well, it was fairly straight forward. We built yet another user control that acts as a Host for any IView. Plumbing some events, exposing some interfaces and we were done.

Oh, I almost forgot… a good introduction to Composite WPF technical concepts is available on the dedicated MSDN page.

The result, so far, is that we are able to develop fast, with clean code, employing good concepts and laying the ground for better testing of our software deliverables.

Reset

March 14th, 2009

From this blog, until now, there was no indication of my work, my profession and my skills. As this year I will reach 10 years in business, encouraged by family and friends, I think it’s time for me to start giving back, to start sharing. So, I decided to start posting about Software Development, Software Architecture and .NET subjects. I can’t promise anything about frequency, but I want to bring quality in each post. I started already a few moths ago to support the community on http://stackoverflow.com. My activities there, answers (and lack of questions) are here: http://stackoverflow.com/users/41345/sergiu-damian.

See you soon!

Schweiz / Suisse / Svizzera / Switzerland

September 27th, 2007

I find myself againg in Budapest airport, waiting for my connecting flight home. I had the chance to catch a glimpse of the famous clean country, independent and very rich in both economical and nature terms. While days passed fast, during my visits to our customer, the nights passed quitely in the cosy Gasthaus Weinhalde (http://www.weinhalde.ch). I loved Zurich and Zurichsee area, where it seams that life has a totally different rythm and feel than in a big american city. You have water, mountains, good roads and multiple nationalities in one small area. In the office, there is no official language. They speak German, Italian, Spanish, French and English. Well, I have to cut the story short because my boarding started. Conclusion: I have to get Oana here someday. It’s definetly worth it!

Denmark

April 3rd, 2007

Being in Denmark for the first time, the first thing that struck me is that for most of the several hundred kilometers spent on the highways, the country seems to be filled with small, scattered villages, where agriculture and farming are the most important things. It displays a tranquillity that I would expect to see in Switzerland. So far, so good. I stayed at this hotel http://www.skodsborg.dk/uk/, by the see side.

Fratii Jderi (Marten Brothers)

November 30th, 2006

Oana and I had a wonderful holiday recently. We decided to take a week off. But, what to do in November, in a country where winters are tough and November usually brings the first snow? Luckily, we found out a great place, in the middle of the mountains, were we found everything we wanted: a warm bed, fresh air, peace & quite and nice & hospitable people. We found a place called “Fratii Jderi” (Marten Brothers), a place built by a man who knows how to live his life, who loves what he’s doing and feels very strongly about his freedom, manifested in a unique place that after one week makes us definetly want to go back there again. There are just a few places we’ve visited during our travels that really impressed us in such a wonderful way. So, why don’t you give it a try? http://www.fratiijderi.ro/

 Cezar, thank you!

 And last, but not least, enjoy some pictures:

The main house and a great view of the village

Just perfect!

A very friendly kitten that we can’t forget:

Very friendly kitten (1)Very friendly kitten (2)Very friendly kitten (3)

A panoramic view of the place (359°):

Panoramic view of Cezar's place

Ajax and the surfer’s pseudo-happiness

October 24th, 2006

During the years, web development has undergone some forward leaps from time to time. AJAX seems a new (already old) development that seems to bring happier users by giving them the illusion that things run faster and smoother. Joel Spolsky has a nice comment on this: http://www.joelonsoftware.com:80/articles/FB4.5.html

BUD

October 13th, 2006

In airlines business, it stands for the Budapest Ferihegy International Airport. I’ve been here for about 24 times in the last 2 years and it still amazes me that nothing changes here. Well, the WiFi free connection is faster than 2 years ago, but for the rest… I always thought that Hungarians are embracing change and improvement easier than Romanians. To me, this airport is so boring. They can do better and maybe they will. But, until then, you can burn 5 hours here only by entertaining yourself.

Western lifestyle

October 10th, 2006

Well, today I saw a glimpse of the western lifestyle. Today, I was paying a visit to a customer in Holland. Travelling 90km in the Netherlands using exclusively the highways took me 2 hours. This makes it an average of 45km/h. Doing this on a daily basis would mean someone would loose 3-4 hours a day with travelling time. This fact of western life is intangible for a Romanian who works and lives in the same town, where distances in time and space are basicly the same no matter if you travel by foot, by bus or by car. So, what are we aiming for? When time is money, and living has a cost attached, we’ll be paying with our own life(-time) for being able to live it. Isn’t this nice?

The first one

October 9th, 2006

Well, today I had some time to burn. So, I downloaded WordPress. A friend of mine pointed me there. To my surprise, it was up & running in no time. Looks promising. I got rid of the old and ugly site, of all the useless pictures and drawings and I started a new page. Now, I’ll go to sleep. Tomorrow I’ll try to set it up and see what it can do for me & you.