Saturday, March 24, 2012

Practical Patterns - Introduction

Design patterns are a key aspect of modern software development. The (re-)use of known patterns is almost universally accepted as a sign of a well-designed system. Resources ranging from community forums and blogs, to magazine articles, to official development guidance promotes their use.

So why do so many software developers continue to develop applications without them?

There is probably not one single answer to that question, but I suspect the problem is mostly due to a simple lack of understanding about patterns and their usage. By that, I partly mean that many developers still don't know what patterns are, or what they are called. But even once that hurdle is overcome, there is still a lack of awareness of the best way to use a given pattern. And using a pattern incorrectly can often be worse than simply cooking up your own solution to a problem.

By their very nature, patterns are language-agnostic. Most discussion and information about them is written in terms of their broad goals, their design philosophy, and their abstract behaviors. Instead of doing more of that, I'd starting what (I hope will be) a recurring series on the practical application of design patterns, specifically in applications written in C#, using WCF and WPF, for .NET 4.5, in Visual Studio 11. (I'll try to avoid too many .NET 4.5isms, or at least point them out when they show up.)

For this first post, though, I thought I'd start with a brief introduction to patterns as a concept. This won't be anything too ground-breaking; if you've read the Gang of Four book then you will probably find this post somewhat repetitive. If you have no idea what the Gang of Four book is, keep reading.

Monday, March 19, 2012

Major Props to Bright House Networks

Just wanted to give some well-deserved kudos to BrightHouse for having some pretty impressive customer service. Decided to upgrade both my standard DVRs to HD and my standard Internet to "wideband" in one weekend. Of course things went wrong, but BH sent out a technician at the last minute at 7pm on a Sunday to fix my DVR. Then their phone support reconfigured my Lightning modem to work with my Gentoo firewall/mail server/etc without even batting an eyelash.

WAY better than my experiences with Comcast, I must say.

Plus now I have wideband, which is clearly wider than broadband and thus better.

Thursday, March 08, 2012

Proxy-Free WCF: Bonus Round:Entity Framework

In a few previous posts, we've seen how to go about eliminating the auto-generated service references from your WCF clients. This is done by using a ChannelFactory and sharing your model objects through a channel independent of the WCF service itself (e.g. a shared assembly.)

In those posts, our model was a very simple, single POCO entity that we moved into a class library, which we then shared between client and server. In practice, your model is probably going to be significantly more complex. It might be something like an Entity Framework model, which we certainly don't want to share in its entirety with our client!

Today, we'll look at how the Entity Framework already supports being used as a data contract for WCF, and how we can extend this to support our proxy-free WCF clients.

UPDATE: See this blog post for the sample code for this article.

Wednesday, March 07, 2012

Proxy-Free WCF: Ditching The Proxy

Last time, we took a peek inside the auto-generated code that makes up a Visual Studio Service Reference. When you strip away all the tooling support and configuration data, what we're left with is a very thin wrapper around a dynamically-generated proxy class, courtesy of the ChannelFactory object.

Today, we'll see how to take advantage of that class directly, and eliminate the need for a Service Reference at all. Along the way, we'll also see how to use this new-found knowledge to help with unit testing and a few other interesting scenarios.

UPDATE: See this blog post for the sample code for this article.

Saturday, March 03, 2012

Visual Studio 11: First Impressions

So, like probably every other C# developer in the world, I downloaded and installed the Visual Studio 11 beta a few days ago. I've decided to start using it for all of the sample code for the blog, so I thought I'd give you some early impressions.

The usual caveats apply, of course. This is a beta so I'm not terribly worried about bugs yet; I'm mostly interested in the new features and enhancements. Also, I'm playing with the Ultimate edition of VS11 but I will probably only end up using the Premium edition, so I'm going to ignore some of the advanced features that aren't part of Premium. That said, lets take a look.

Thursday, March 01, 2012

Proxy-Free WCF: What's In A Proxy

Writing services-based applications using Visual Studio has always been fairly easy, dating all the way back to the web services support in Visual Studio 2003. These days, services means WCF services, but the IDE support has remained largely the same. You just need to supply Visual Studio with the URL for your web service, close your eyes, tap your heels together, and poof! You get a fully-functioning WCF client proxy class all ready to go.

This process works very well for simple applications, or applications using third-party web services. But when you start writing applications against your own services, and factor in things like deployment, unit testing, etc., the default client proxy generate can really start to work against you. Fortunately, you do not need to use these client proxy classes: WCF includes everything you need to generate them on demand, at runtime, with only a tiny bit of effort.