Welcome to Steve Smith's blog!

  • Find Debug Assemblies using Glimpse

    A new feature in Glimpse.AspNet 1.9.2 will display whether each assembly in your web site’s bin folder was compiled in Debug or Release mode. At development time, Debug mode is fine, but you want to avoid shipping Debug assemblies to production since there are performance costs associated with these assemblies.  You can determine for yourself whether a given assembly was compiled in debug mode using this code, which also links to the performance issues. Under the Environment tab in Glimpse, you can scroll down to view the Application Assemblies section. The new column, Build Mode, shows for each assembly how it was compiled.  In your production deployments, you want to make sure … more

  • DogFoodCon Session on DDD with ASP.NET MVC

    Yesterday I presented at DogFoodCon, giving a slightly modified version of a talk I gave a week earlier at FalafelCON in San Francisco.  The session provides those with little knowledge of Domain-Driven Design with a rapid overview of some key concepts and patterns used in DDD, and wraps up with a brief demo of a simple Guestbook application that begins as a monolithic everything-in-the-controller MVC application but is improved using some DDD-based techniques.  The slides are available on Slideshare and embedded here: Add Some DDD to Your ASP.NET MVC, OK? from Steven Smith Both times I gave the talk, I ran out of time to show everything I wanted in the demo (sorry, it’s a big … more

  • Finding Copies of Images Online

    Obviously it’s very easy to download and reuse images on the Internet. However, if your business depends on such intellectual property, you may need to take steps to prevent unauthorized usage of your images. There are many ways you can mark your images to later prove they are yours – that’s a topic for another day – but you may not know there is also a very easy way to find other images and where they are located given one.  Let’s take a simple example from Apple’s website, where they show off some pictures of the iPad Air: The URL for that ladybug image is: We’ll need that in a moment. Google Image Search In … more

  • Anthropomorphism Raised to Organizationalism

    Recently on twitter, Michael Feathers raised some interesting points about how the media tends to naturally group individuals together, especially “on the Internet”: As he notes, we already have a word for treating inanimate objects as if they were alive, sentient, humans: anthropomorphism: Obviously when we do this, we’re telling a small lie. Non-sentient objects do not have feelings or intentions, but we sometimes like to confer these attributes on them because it makes for a more interesting story.  Telling somebody “My car hates me.” is often more interesting than “My car is unreliable.”  Unfortunately, we don’t appear to have a word to describe taking this up a level, when … more

  • Logging in Entity Framework

    When working with any ORM tool, it can sometimes be helpful to see just what, exactly, is being sent to the underlying data store.  This can help identify bugs as well as performance issues in how the query is being performed (or how many queries are being performed, in the case of SELECT N+1 problems).  There are several existing tools available that provide assistance with this:

    SQL Server Profiler

    EFProf (third-party commercial tool)



    Sometimes, though, you want to be able to log what EF is doing to a standard logger, whether using the built-in System.Diagnostics calls, or a logging tool like log4net or NLog.  In this case, there’s a very … more

  • RGRC is the new Red Green Refactor for Test First Development

    Test Driven Development (TDD), aka Test Driven Design, aka Test First Development, has long had a simple, virtuous cycle at the heart of its workflow: Write a failing test (run the test(s) – they should be RED) Make it pass in the simplest way possible (tests are GREEN) Now clean up the code (eliminate duplication and other code smells) (REFACTOR) When following this workflow, one can make steady, incremental progress on a project or problem with minimal risk of spinning one’s wheels for hours on end or trying to take on too large a task and becoming overwhelmed by its complexity.  It’s a great approach that I’ve practiced on countless occasions, and which you can easily practice by … more

  • Getting Started with Castle Windsor

    My preferred IoC container is StructureMap, but I’m going to be working with a client who uses Castle Windsor as their standard container, so I decided to learn a bit about it this week.  I created a simple console application and included some interfaces and implementations to see how things work.  Registering individual interfaces and wiring them up to their implementations is pretty straightforward: Getting resolved types out of the container is as well.  In this case, Greeter requires an IGreeting and an IWriter in its constructor: While you’re learning how to work with the container, it can be useful to see a list of everything that is currently registered.  I … more

  • JavaScript Date Tips

    The other night at the Hudson Software Craftsmanship meeting at the Falafel Software training center in Hudson, Ohio, I did the Red Pencil Kata using JavaScript.  Although I’ve run into it in the past, I was stuck for a little while (I was the odd man out without a pairing partner to help find these things faster) due to one of JavaScript’s “fun” date conventions.  Being a C# developer primarily, there are many small things I have to remember that are different between JavaScript and C# (like where to declare variables, for instance).  In this case, it was the code for generating a particular date that bit me.  At one point, I wanted to generate a … more

  • Where to Declare Variables in C# and JavaScript

    Both JavaScript and C# belong to the C family of languages.  They share curly braces and semi-colons, and in fact there are many cases where the exact same code will execute (correctly, in most cases) as either language.  However, there are certain best practices that are unique to each language, and where variables should be declared is one of them.

    Declaring Variables in C#

    In C#, it’s generally best to declare variables just before they’re used.  Like any convention in programming, there’s some debate about this, but this rule is supported by well-respected books like Clean Code and top-voted answers to questions like this one: Where do you declare … more

  • Ensure You Are Not Adding To Global Scope in JavaScript

    A key best practice if you’re writing JavaScript code is to avoid adding objects to the global scope.  There are several good reasons for this – globals add coupling, it makes it easier for disparate libraries to break one another, etc.  A general rule of programming is to avoid global scope, in fact.  Unfortunately, JavaScript makes adding things to global scope very easy.  Consider this bit of code: In this example, we have a function, within which we set a variable and then use some jQuery to modify a div.  However, because we didn’t specify the “var” keyword, we’ve actually just added a new object to the global scope: message.  In fact, if some other … more

  • Free Stock Photos for Presentations

    If you’ve graduated from basic death-by-bullet-point presentations to something that will keep your audience interested, you’ve probably encountered the problem of “where can I find the perfect image to underscore my point,” preferably without having to pay an arm and a leg for it.  I recommend books like Presentation Zen to learn more about how to amp up your presentations, and that book makes some (dated) recommendations for places to go to find images.  I’ve used many different resources for my developer conference presentations and Pluralsight courses, and I thought others would benefit from this list (and probably future me as well, since I frequently find myself referring … more

  • Resolving Dependencies in ASP.NET MVC 5 with StructureMap

    In a previous post I showed how to use StructureMap with ASP.NET MVC 3.  It’s been a couple of years, so I figured it was time to update that article with the steps for getting StructureMap working in ASP.NET MVC 5.  If you’re interested in learning more about how to develop applications in a loosely coupled fashion, I highly recommend my course on SOLID Principles of Object Oriented Design to learn more (in particular, the Dependency Inversion Principle). StructureMap is my preferred IOC container / dependency injection tool for .NET applications.  It’s free, performs very well, and has a number of very useful features that make it very productive to work with.  One … more