Sunday, August 18, 2013

I caught the end of a talk by John Crowe on Inversion of Control at Austin Code Camp.

I ducked out of Eric Lawrence's Fiddler talk yesterday at Code Camp early and found Mr. Crowe's talk instead. It was called "Effective IoC with Dependency Injection." By the time I walked into the room he was wrapping up and taking questions. He had a slide up on service locator and I asked when one would want to use service locator in lieu of dependency injection. His answer boiled down to: "Never!" Service locator makes it harder to run tests as one will have to fabricate an IoC container inside of the tests. If you ever abandon service locator for dependency injection you will have a lot of work to do in the name of replacing all the service locator calls sprinkled throughout your code. Someone in the audience asked about the performance hit one takes with IoC tools and John asserted that is wasn't worth worrying about. If you are interacting with a database, you might as well worry about your performance problems there. Eric Hexter mentioned that there was an article by Dan Holme from 2011 which listed some IoC tools and rated them on performance. I tried to find it online for this blog posting but I couldn't. John said that one should keep the wire up for dependency injection in Global.asax.cs (or wherever it may be) simple and clean. There should not be other code bleeding in here. Jeffrey Palermo suggested that he views the code here as just another global variable or singleton and encouraged not trying to make it something more. In an earlier session on AOP by Matthew D Groves, both Castle and PostSharp were brought up as potential AOP tools. Castle relies on appending AOP conditions to mappings at StructureMap's configurations for dependency injection where PostSharp does not. I wonder if John would thus find PostSharp "better" in regards to not polluting IoC mappings. I tried to take a photo of John during his talk, but the pictures I took all came out bad. (He had the lights dimmed in the room to project.) I ultimately stole this picture of him at the day's end in the parking lot of the Echelon center (where Saint Edwards has its North campus) after Code Camp let out. It's cool that his shadow is Nosferatuesque.

Service locator is scary.

No comments:

Post a Comment