I don't want to be a wet blanket, but someone's got to put a stop to the IoC love fest going on out there.  An Inversion of Control (IoC) container , for those of you were aren't yet familiar, allows you to retrieve instances of objects at runtime.  A relatively common solution to a common problem. In the .NET world there is no lack of choices of IoC containers:

(I won't go fully into IoC, but If you'd like more resource you can read Martin Fowler's article on the subject or post specific questions in the comments or contact me through.  Read on, there is value here in this post for you.)

Let me state clearly now, IoC containers are a means to an end and NOT a feature of your application. The goal is to have loosely coupled applications, IoC containers help get you there, but you can absolutely have a loosely coupled application without an IoC container (see the Gang of Four creational patterns).

Occasionally I'll hear some comment about IoC and how great a certain container is or how an application would be so much better if another, sexier, container was used.  Here are some recent tweets that illustrate:

  • Man i love #StructureMap, always finding new things i can do, and have fun doing them
  • really need to look at structuremap, but we''ve invested a lot into castle with our own facilities/resolvers/etc
  • Ninject is da bomb!
  • Switched from Windsor MicroKernel to Ninject in 10KLOC project in < 1 hour by creating a little proxy. Now to complete the conversion.
  • It is a talk on Castle Windsor so i guess Ninject will not do.
  • Can't imagine why somebody would use Ninject beside the fact that it's PURE AND UTTER AWESOME. Yeah! Ninject FTW.

Some of the statements above are probably innocuous, but some rub me slightly the wrong way.  Specifically the two comments above about switching from one container to another. There are probably times when the choice of one container over another makes sense, but I would bet that these scenarios are the exception and not the rule.

Choosing one container over another won't make your application a success, the architecture, or lack there of, will have far more of a say on your application than will your container choice. As yoda might say, "The container you choose does not a good app make".


 
Categories: IoC | Rant | Tools | Windsor

December 9, 2008
@ 01:09 AM

Over the past week I've had the distinct opportunity to have a first-hand look into NHProf, Ayende's upcoming profiler for NHibernate.  It's been an honor to be part of the team that is putting NHProfiler through its paces.  While NHProfiler is still in private beta it is very impressive and I want to let you peek inside.

This evening I decided to sit down and spend some time poking around an application and watch NHProfiler to see if anything seemed out of sorts.  Here's what I found:

Easy To Understand

You can get by without purchasing NHProf, from what I see there's nothing you can't "figure out" yourself.  NHProf is a lot like ReSharper or CodeRush, you can get by without it, but why would you want to?  Here's what I mean, you can pop open SQL Server Profiler and see what is being executed:

image

That's messy but take a look at how NHProf collates the data:

image

Relevant

You can sift through the SQL Server Profiler trace if you'd like to but NHProfiler does a great job in giving you the same information, just presented better.

image

From this view I can see that five queries were run and I can see that three of the same queries are being issued which might point to an area where there is some tweaking to do.

Performance Gains

We all want our applications to run faster.  We want speed and performance but often times its takes quite a bit of time to find performance problems and their subsequent fixes.  NHProfiler allowed me to very quickly find some queries that didn't need to be executing and tweak some code to eliminate those calls.  Since I can see the code that NHibernate generates I can also make modifications to query I'm submitting to NHibernate for further performance gains.

In a very short amount of time (the writing of this blog post has taken several times longer) I was able to reduce reduce data access time by a factor of nearly 10.  How do I know that, I have the hard data to prove it.

Before:

image

After:

image

Conclusion

If you use NHibernate, NHProfiler is a must.  By using NHProf to observe my applications I'm able to save my time and not have to burrow through SQL Server Profiler or wonder what is going on at the data level.  I am quickly able to observe what is going on and when and make any necessary modification and then observe the outcome.  While you can use Visual Studio without ReSharper or CodeRush many of you out there have found you just don't want to.  After using these productivity tools you find that you're able to work with less friction.  NHProfiler is the same way, you can work without it, but I highly recommend against it.

Keep your eye on Ayende's blog for information coming soon.


 
Categories: NHibernate | NHProf | Tools

October 21, 2008
@ 10:34 PM

Last week I posted the first in a series on Mass Transit, an open source enterprise messaging system.  This series is my public exploration into messaging for our eCommerce application.  In this post I'm going to dig in to see an actual working example.  I like to see something work, then dig in to figure out how it's all put together.  We'll take a look at a simple publish subscribe example to see the messaging in action.  In later posts we'll dig in deeper into the guts of MassTransit.  That said, let's see some MassTransit in action!

Getting Started

I've downloaded the MassTransit source from the Google Code repository and am going to run one of the samples provided with the source.  We'll look at their "PublishSubscribe" sample.

image

Project Structure

image Opening the solution reveals nine projects, a few more than what I would consider a simple sample, however don't let the solution scare you away.  It turns out that you can for the most part ignore five of the projects, the mass transit infrastructure projects.

There are four parts to this solution that are relevant and we'll focus on those:

  • Client - The client represents the application that wishes to leverage messaging.  It plays the role of publisher in this example.  It is worth noting however that in this example, as we'll see, this project is also a subscriber.
  • Security Messages - This is a pretty simple project as it should be.  This project encapsulates the strongly typed messages that will be passed throughout the system.  By having the messages in their own light-weight assembly we can keep our messages separate for their consumers.
  • Server - This project acts as the subscriber.  In a normal scenario this server may be sending out emails or logging particularly interesting things as messages come through or whatever else you may have a need for.  Like the client project, we'll see that this project also plays dual roles, the subscriber as mentioned and also a publisher.
  • SubMgr - The subscription manager, is quite a mystery to me.  It may not be obvious, but the subscription manager is needed to get everything to work.  As Dru explains it to me, it is the glue.  In my first go around with MassTransit, I created a client and server and was frustrated when nothing was working.  Talking with Dru, he quickly pointed out my error, I had no Subscription manager.  In the following posts I hope to clear up some of the mystery for myself around the subscription manager.  My understanding at this point of the subscription manager, which may be a bit simplistic, is that it pushes the messages to each of the queues which are interested in the message.  A publisher publishes a message, the subscription manager is the one that ensures that it ends up in the appropriate queue(s) for consumption by various subscribers.

Getting Setup

image In order to get this sample going you first have to create the MSMQ queues that this sample expects:

  • mt_client
  • mt_pubsub
  • mt_server

You can create these queues in the Message Queuing area of the Services and Applications snap-in in the computer management area on your computer.

Seeing Is Believing

Now that we've got the project set up let's fire it up and see what we get.  Since we need all three applications running at once, the client, server, and subscription manager we can take advantage of a cool feature in Visual Studio, multi-project startup.

With multi-project startup you start any number of projects in your solution.  From the properties dialog for the solution we can choose which projects we want to kick off.  (It is worth noting the order in which I have these projects launching.)

image

What's Going On

When you run this example, the client application will ask you to enter a new password.  When you type in a new password  you will get a nearly instantaneous response letting you know the password was updated.

image 

The thing to bear in mind here is that at the point you hit the <enter> key submitting your new password, the client publishes a message and then it is done.  It appears instantaneous but you'll want to keep in mind that it is asynchronous.

The Flow Of It All

image The diagram to the right illustrates what is going on once you hit the <enter> key.

  1. The client publishes a RequestPasswordUpdate message (see the Security Messages project in the solution for this message object).
  2. The server in this case consumes the RequestPasswordUpdate message.  When it is notified of the message, it logs the new password, then...
  3. The Server publishes a new PasswordUpdateComplete message.
  4. The client consumes the PasswordUpdateComplete message and in so doing writes to the console that the password update is complete.

It is worth noting here that the client knows nothing of the server and the server knows nothing of the client.  Our example could easily expand to have multiple clients (think for example a windows app or multiple web servers in a farm).  Likewise there could be multiple server instance, each consuming different messages.  In other words, we are very loosely coupled, which is a good thing.

Conclusion

I hope this introduction to the MassTransit was beneficial.  Now that we've seen the example working, in the next post I'll revisit the idea of durability.  We'll augment this example and simulate a breakdown in infrastructure and see what durability really means, which is really at the heart of this fantastic open source library.


 
September 2, 2008
@ 02:59 PM

How cool is Google Chrome (new browser from Google)?  Way cool...like "too cool to run on your machine cool"

image

Thumbs up though for their error screen, just wish I didn't have to see it

image


 
Categories: Musings | Tools

May 10, 2008
@ 03:49 PM

imageLast year when I built a new machine I purposefully built the machine with lots of power so that I could have multiple different environments and insulate myself from the loads of crap-ware that inevitably ends up on my machine.

Virtual machines allow me to download and try some utility in a sandbox where I know I can return to a previous state.

I opened one of my virtual machines and saw the screen posted on the right.  If this were on my host machine I think I'd need a new pair of underwear.  I don't have the time to rebuild a machine and so screens like the one of the right scare me.  However that is a virtual machine that had the ASP.NET MVC Framework Preview 2 on it.  So, am I going to try and diagnose?  Nope.  Just create another...it's beautiful.

 

 

 

 


 
Categories: Hardware | Musings | Software | Tools

"TopicProvider.cs," the developer shouted, indicating someone in the room had committed an updated project file, but not the new file.  Humbled, I quickly went to my sandbox and added and committed the file.

"TopicProviderTests.cs," came another shout.  Again quickly I added the file.

Feeling embarrassed that I missed committing two files, I noticed that I had no icon overlays on my files, indicating my status with the CVS repository.  No matter what I did I couldn't get the overlays to come back, and boy I was missing them.  You don't realize how often you use the visual cues they provide until they're gone!

I tried:

None of the above worked.  The only thing I could think of was that I had recently installed Office 2007, which installed a folder synching program called "Groove".  I thought maybe Groove worked similarly to CVS and provided some icon overlay to notify you of a change.

Some digging provided the following provided the following from the TortoiseCVS Page:

The number of overlays allowed by Windows is limited to 15 in total. Windows itself uses 4 of those, leaving the remaining 11 to be used by other applications. If you have other software installed that uses icon overlays, the limit may be exceeded, causing some overlays not to be shown.

To resolve this problem, either uninstall the other software altogether, or manually remove one of the other icon overlay handlers. This can be done by editing the registry. Use at your own risk! You can delete [unused] entries at HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/ShellIconOverlayIdentifiers.

A quick check of the registry key above showed the following:

RegistryWithGroove

Notice the number of Groove icons.  Windows sorts the registry based on Alpha, and this must've been found somewhere else, because if you look, TortoiseSVN stores it's overlays by preceeding the name with an integer.  Very smart!!

My TortoiseCVS overlays disappeared when I had installed Groove due to the limitation that Windows has on overlays.  I uninstalled Groove and there appeared my TortoiseCVS overlays.  Here's my registry after:

RegistryWithoutGroove 

Completely evolutionary thinking that prompted someone in the SVN camp to notice this problem and figure they should make themselves first in the registry all the time and therefore never have users experience what I did.


 
Categories: Software | Tools

This is the second-edition of a post I made a long time ago on a different blog.  I'm posting it because of a post made by Eric Bowden about his new approach to personal email management.

"So here is the approach:  I have a dedicated domain name "scrappydog.com" with just one email user (me).  All email to any email address in the scrappydog.com domain lands in my inbox.  This allows me to created a separate dedicated email address for every organization I do business with, and I can create a one off random address for any interaction I want."

In the comments Tony Toews quickly points out a flaw in Eric's plan:

"However, once the spammers start using your domain in their spam emails you will be inundated with bounces.  Several of my domains are getting hundreds of bouncers per day.  And you will be forced to created individual email accounts on your server.  So keep track of all those account somehow."

Currently I have a two tools (both free) that I use for spam management beyond the provided spam filters:

SpamGourmet

SpamGourmet.com is a free service that allows you to generate disposable email addresses.  Once you create an account, you can create unlimited disposable email address.  If my username is "Tim", I create a disposable email address using the following pattern: <disposableIdentifier>.<maxEmails>.<username>@spamgourmet.com. If I was signing up for an account with CNN.com I would use the email address CNN.20.Tim@spamgourmet.com.

Any email sent to that address will be forwarded to my real email address.  I use this service for websites that require an email address for signing up and I may wish to receive emails in the future.  Having SpamGourmet allows me to make sure the website hasn't sold my email address.  If my email address is ever sold I will know who sold it, by the identifier I used to create it.  Also, given that I've set a maximum number of emails, if it does get sold, I won't get inundated with emails.

It should be noted that SpamGourmet comes with many slick advanced options, whereby the situation described above by Tony can also be averted easily.

SpamBox

SpamBox.us allows the same type of service, however you don't need to create an account.  Again, all emails to that account are forwarded to your real account which is hidden.  SpamBox is time based.  You have to go to their website to create an email address and while creating the address you specify how long before the email address is deleted.  I use this service for websites that require an email address for signing up and I'm fairly certain I don't care if I ever hear from them again.

Do I trust SpamBox and SpamGourmet not to sell my email?  Not entirely. They say they won't, but  you never know.  The way I see it though, is that if they do in fact sell it, it'll only becoming from one source rather than 35-50 accounts I have opened around the internet.


 
Categories: Tools