Configuring IUnityContainer

I’m using the IUnityContainer from the Composite Application Guidance in my current Silverlight project for Dependency Injection and this morning, I came across something that I couldn’t find documented anywhere. Initially, all my registered dependencies were being created using other dependencies that I had registered with the container. For example, I had the CustomerOrderService below and it was created using an IEventAggregator that was already registered in the container.

    public class CustomerOrderService : ICustomerOrderService
        public CustomerOrderService(IEventAggregator evAg)
            this.eventAggregator = evAg;

I was just registering my service with the container and letting it do all the work.


However, this morning, I wanted to add a simple string to my constructor so that I could pass in the URI for a web service instead of hard coding it in the service class. After digging around a little in the docs and eventually just playing with the code until it worked, I came up with two ways of doing this.

First, I modified my service to have two constructor arguments:

    public class CustomerOrderService : ICustomerOrderService
        public CustomerOrderService(IEventAggregator evAg, string uri)
            this.eventAggregator = evAg;
            this.baseUri = uri;

Then, I came up with the two ways to register this service in code with the container. First, you can tell the container how to configure your dependency registration.

    new InjectionConstructor(typeof(IEventAggregator), "URI GOES HERE"));

When the container is asked to create a CustomerOrderService object, it is configured to send in an IEventAggregator instance that it resolves internally and the URI string above. Of course, in a real world app, that URI would actually be a URI that I get from configuration.

Alternatively, you can tell the container what to do when you register the type:

    new InjectionConstructor(typeof(IEventAggregator), "URI GOES HERE"));

This is a little cleaner because you’re going to have to register the type anyway and it makes sense to configure it at the same time.

By allowing the developer to specify an InjectionConstructor to use, the UnityContainer gives the developer a much more flexible way to register his dependencies.

PS: The Google Syntax highlighter and my new WordPress theme don’t apparently play well together. Or at all. So the code is displaying in a ridiculous way. If you need an actual example, feel free to drop me a line in the comments and I’ll send you one. It may be time to separate my tech blogging out from The Experiment.

The Gap Between Taste and Ability

I recently ran across this video of Ira Glass talking about the huge gap that exists between your taste in creative endeavors and your ability to create. I’ve always implicitly known this gap existed but this is the first time I’ve heard or seen it vocalized so clearly. I think most creative people struggle with what they see as the inferior things they create and what they know is actually good. Oftentimes, creative people are extremely hard on their work, even though the consumers of their work think it’s very good. This is because of that gap.

Ira suggests that the way to close that gap is just to produce a huge quantity of work, whatever it is that you want to get better at. For writing, this is the spirit behind National Novel Writing Month. The aim there is to just write, quantity over quality and get past the inner critic. It’s a useful exercise even if done in slightly less extremes like writing in a journal for an hour or playing scales for an hour or solving Project Euler problems. Of course, to really improve, it takes not just quantity but also time.

Current evidence says that it takes 10 years of constant practice to truly master anything whether it’s painting, writing, coding software or playing professional golf. It’s something that’s difficult to comprehend especially in the day and age we live in where everything is immediate. But the fact is, if you want to be truly great (or even just better than average), it takes a huge quantity of whatever it is you want to improve in to get the job done and a great deal of time to let it soak in.

I struggle with this gap a lot, both in my daily work and in my writing. I find my internal critic to be quite vocal and my internal creative genius to be shy and reserved. I’ve written about this before, the critic taking hold of both my voice and the publish button, rendering what might be perfectly good content to the dustbin of the drafts folder here at The Experiment. I write a lot that is never going to be published but I’m not sure you improve as fast when you aren’t put content out where people can see it. This is similar to the agile way of writing software, getting it out to the users quickly so that they can tell you where it is right and wrong. Of course, all analogies fall short somewhere and with writing, I would never want my audience to dictate what I produce because if that happens, it’s no longer my voice producing the work. But it’s a useful analogy in that producing a lot of work is the fastest way to improve.

I find that the hardest part of creating is just doing it for extended periods of time amid the thousands of distractions that demand attention all the time. Right now, instead of focusing on this post, I’m also monitoring the Cavs-Magic game, checking my email, listening to music and who knows what else. Doing things for 15 minutes at a time never aids improvement. I find that my attention is constantly fragmented unless I very deliberately and consciously eliminate distractions. When I do this, as I fight through the anxiety of not paying attention to things that don’t matter, I discover that my productivity goes up as well as the quality. The difficulty lies in unplugging for the time necessary to achieve that productivity.

In the end, the only way to quiet the critic is to constantly produce content of a long period of time. Eventually, assuming some level of underlying talent, the gap can be closed or at least narrowed to an acceptable distance.

A Timely Tradition

This weekend is Memorial Day Weekend and for the past three years, we have hosted what we refer to as “The Meatfest” at our house in early celebration of Memorial Day. This year will be no different except that the people on our guest list have mostly all agreed to drive to our house out in the boonies instead of respectfully declining to do such an odd thing in the past. We have 35 positives so far, a record, which strikes both great joy and great terror in my heart, Joy because parties mean beer and beer is fun, Terror because cooking enough dead cow, pig and fowl for 35 people is a rather large challenge.

I drove up to Rehoboth Ranch this morning to get the brisket, ribs, chicken and sausage. Their available briskets were a little on the small side so I’m going to add a regular non-grassfed, unorganic, fatty, Omega-6 having, Albertson’s one to ensure enough food. Also, because they do grassfed beef, the briskets are infinitely more lean and I worry about what I might produce on my virgin experience in smoking a lean brisket. This worry was compounded as the proprietor explained how it had a tendency to dry out if you screwed up. Yay Anxiety!

The Oprah brisket will go on the smoker tomorrow AM for its long, 18 hour journey from “big chunk of inedible gristle” to “sweet mother of mary that is good shit heaven on earth”. It should finish up around midnightish, plus or minus a couple of hours. The Richard Simmons brisket will make a smoky appearance on Sunday morning promptly at 6 AM to ensure readiness by 2 PM (it’s a much smaller brisket, remember so it shouldn’t take more than 7 hours). Richard will finish up in the oven starting around 10 and the ribs will do the smoky dance of love in his place. Chickens get violated around 11 and the sausage will just get thrown on the grill to warm and crisp up, being fully cooked all ready.

We’ll have the usual assortment of BBQ sides and condiments. We may have margaritas. We hope to not have rain but that’s up to the BBQ gods at this point. I may or may not write about updates as the weekend progresses, depending on how it progresses relative to being ready at 2 PM on Sunday for the hordes.

Green Shoots Are Sometimes Weeds

As any gardener will tell you, healthy lawns hardly ever have weeds in them. This is because when a lawn is healthy, it is lush and thick and weeds don’t have a chance to grow. Weeds only show up in a lawn when there is something wrong with the underlying soil or lawn. If the lawn is unhealthy or the soil isn’t providing the right nutrients, weeds have a better chance of germinating and propagating throughout the lawn.

There has been some talk of green shoots in the economy lately and the stock market has certainly been doing its part with the S&P up over 30% from its March lows. There seems to be some optimism out there and people are starting to talk like the worst recession since 1930 might end in a V rebound to prosperity. The question is, are the green shoots really a healthy lawn rebounding after a cold winter or is the lawn dead, the soil useless and thus what we’re seeing are essentially weeds?

I’d argue we’re getting awfully excited about a bunch of dandelions. All of this excitement is almost certainly wishful thinking and the people pouring money back into the market right now are likely to be very disappointed come summer when it gets hot and the weeds shrivel up and die. The data over the past 3 months has been overwhelmingly negative yet because the “stress tests” our esteemed government ran on the banks came out positive (ignoring the fact that there was no negative option, it was set up as win-win), the market has acted as though nothing bad was going on. S&P earnings are down an unheard of 90% over the past 20 months, unemployment continues to rise and we’re about to go through the bankruptcy of two large automakers in the US. There is a pending disaster waiting in the wings of commercial real estate and foreclosures are increasing while home prices continue to fall. The state of California may go bankrupt or our federal government will be forced to bail them out, either outcome leading to a ripple effect throughout the economy.

Every bear market has runs of 20-30% that trick people into putting money back in at the highs before crushing their hopes of a recovery by testing new lows. We may not see the lows in the S&P that we saw back in March but I have serious doubts that the run up we have recently seen is sustainable given the overall severity of the recession we are in.

Things To Do About Town

If you’re in the DFW Metroplex and want to listen to some good live music this Thursday, head out to Tolbert’s Restaurant to hear The Vintage Vibes do two sets of 50s jump, jazz blues music. They are a great band and this opinion is in no way influenced by the fact that I am married to the lead singer. If you don’t go see them this week, you may not get to see them again until July and that would be a travesty. Go. Do as I say. First set starts at 8:30.

The New Design

A couple of weeks ago, the 10,000th visitor found their way here to The Experiment. I’ve been considering how to mark this momentous occasion (even though those visits aren’t particularly reliable and certainly, my sitting at home hitting F5 trying to drive up my visit count doesn’t help. Not that I would ever do that). I decided to celebrate in what can only be described as an odd way. I’ve changed the theme of the site to the current one, The Erudite by Soma Design and I’ve taken the tracking code for both Sitemeter and Google Analytics off the site.

Let me explain. I’ve been thinking about a new theme for a little while. The old theme was really cool and was certainly an improvement over my past ones. However, it wasn’t quite “me” and it tended to be a little too busy for my tastes. About the same time I started thinking about a new theme, I started to think about what I really wanted to get out of writing here. Many of my posts aren’t particularly thoughtful and while I will probably never stop posting human Taser guinea pigs and people falling down escalators while a cat plays a keyboard, I’d like to focus more on my writing, on my thoughts on a variety of subjects and how I express those. Essentially, I’d like to improve my craft of writing and find out what my voice really is.

In a supreme case of serendipity, WordPress had a notification of some new themes up on the WordPress dashboard and I happened to see The Erudite one. It’s billed as a theme for writers and readers and clearly, it lives up to that billing. It’s very clean and the only thing to focus on is what’s written here. I decided to update to it and in the process, to stop worrying about how many people were visiting my site or what my daily average was (big decision for a data junkie). I’m just going to write and see what happens.

I hope that people continue to comment because I won’t really know you’re reading anymore (Hint: I knew some of you came here because I had your IP address or incoming domain name logged in Sitemeter. Like say if you came in to check out what I was writing while you were supposed to be working at SMU. 🙂 ) But even if people don’t, I’m hoping that by moving to a very clean, word focused blog design and removing the distraction of how many people were visiting on any given day, I can focus more on what I have to say. I’m attracted to other voices on the web who have thought provoking ideas and I’d like to join that small chorus with particular ideas of my own. We’ll see how it works out together.

Breaking Up The Team

What would happen if midway through the the NFL season last year, the Pittsburgh Steelers, standing at 6 and 2 and leading the AFC North, had decided that their football season was over and disbanded the team? Or what if they decided to move Big Ben to the training squad because he was a prime performer and the training squad wasn’t really performing very well? What, you say? This would never happen?

No of course this would never happen for a variety of reasons not the least of which is that a team doesn’t just disband. A team doesn’t take their best performers and move them onto another project because that project is sucking wind. A team may lose a player here and there due to injury or trade or retirement but there is a sense of continuity to a team that exists above and beyond the sum of the team’s parts. A team has common, long-term goals like “winning tonight’s game”, “winning the division” and “keeping our superstars with the team”. Successful teams of all types typically have a common culture and no divas. Or at least the divas are under something resembling control. Even on NBA teams, where there are often divas of extraordinary divahood, winning rarely comes consistently unless the rest of the team buys into both the system and the superstar. Conversely, on bad teams, you may have one of the greatest players ever (see: Kevin Garnett pre-Boston Celtics) and still lose all the time.

This is true of all kinds of teams. Without some semblance of stability, culture, direction and goal, teams fail. In fact, they often implode. And yet, we in the software industry continue to call groups of people “teams” when they are at best, loosely grouped collections of individuals with similar skillsets working temporarily on a common project and at worst, highly dysfunctional trapeze artists who would like nothing better than to cut down the safety net and install 2 ounces of extra weight in the left side of their fellow coders balance bar. Project teams are not teams.

This is one of the gorillas in the room of current software methodology. We talk about software teams as if they want nothing more than to succeed when in fact, oftentimes, they could care less and may even have motives to foster failure. Of course, you could argue that we come up with methodologies to standardize these poor teams. But then someone might call you a cynic.

Granted, there are teams like this in the sports world but they don’t typically stay teams very long. They are broken up, sent away and rebuilt with the goal of having a real team. But in software, dysfunctional teams may stay together for office political reasons and completely successful teams may be disbanded in an effort to spread the success around, ignoring the fact that the team may have been successful because they were a team. We continue to treat software teams as if they are completely different from any other type of team we have ever encountered in reality.

As long as we keep trying to treat the symptoms of the disease instead of the actual disease, we’ll continue to have an industry that languishes. Stability is the critical component of the long term success of a software development team. Doing anything that undermines that stability contributes to the continued failures in software development that we keep trying to cure with a new methodology. A solid, stable, professional team can write software using any methodology. It’s only because we refuse that stability that we have to have silver bullet methodologies to try to cure so many of the symptoms of the disease.

Just In Case

If you’re ever thinking about volunteering to be Tased for whatever odd reason you have cooked up, realize that you will probably sound like this when it happens.

The Nibroc Trilogy

If you’re in the DFW area, you should take time this weekend and go see the first play in the Nibroc Trilogy currently being performed in the Theater Too space at Theater Three. The trilogy is being put on there over the next few weeks. It tells the story of a young couple who meet and fall in love in the early 1940s. Echo Theater is actually putting it on at Theater Three.

The first play is Last Train To Nibroc and we saw it last weekend. It also runs this weekend. It’s well cast and the actors do a fine job. Because the theater space at Theater Too is so intimate, there isn’t a bad seat in the house and you really get to see the emotions and interplay between the two actors. The reviews have been quite good and if you’re looking for a reasonably priced evening of good theater, this should fit the bill.

Each play of the trilogy stands on its own so if you can’t get out this weekend, you can go to any of the other plays coming up. I hope you can get out and support local Dallas theater.