<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Grubbsian &#187; Uncategorized</title>
	<atom:link href="http://www.thegrubbsian.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thegrubbsian.com</link>
	<description>Writings on .NET, Ruby, JavaScript, HTML/CSS, Design, and all things Web.</description>
	<lastBuildDate>Sun, 01 Aug 2010 20:57:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Deep Validation with DataAnnotations</title>
		<link>http://www.thegrubbsian.com/2010/08/01/deep-validation-with-dataannotations/</link>
		<comments>http://www.thegrubbsian.com/2010/08/01/deep-validation-with-dataannotations/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 20:57:19 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=320</guid>
		<description><![CDATA[The following attribute will allow complex child properties to be validated when using the Validator.TryValidateObject in System.ComponentModel.DataAnnotations.]]></description>
			<content:encoded><![CDATA[<p>The following attribute will allow complex child properties to be validated when using the Validator.TryValidateObject in System.ComponentModel.DataAnnotations.</p>
<p><script src="http://gist.github.com/502736.js?file=ValidateChildAttribute.cs"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2010/08/01/deep-validation-with-dataannotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NInject vs. StructureMap vs. I Made This</title>
		<link>http://www.thegrubbsian.com/2009/04/24/ninject-vs-structuremap-vs-i-made-this/</link>
		<comments>http://www.thegrubbsian.com/2009/04/24/ninject-vs-structuremap-vs-i-made-this/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 21:10:46 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=195</guid>
		<description><![CDATA[As I&#8217;ve mentioned before my team is working on a large scale ASP.NET MVC application and we&#8217;re using dependency injection to decouple our data access layer from the application. Initially we were using NInject as our IoC tool of choice. It&#8217;s lightweight and has a really nice configuration DSL and it&#8217;s pretty fast. The problem [...]]]></description>
			<content:encoded><![CDATA[<p>As I&#8217;ve mentioned before my team is working on a large scale ASP.NET MVC application and we&#8217;re using dependency injection to decouple our data access layer from the application.  Initially we were using NInject as our IoC tool of choice.  It&#8217;s lightweight and has a really nice configuration DSL and it&#8217;s pretty fast.</p>
<p>The problem arose when trying to get NInject&#8217;s scope caching to work.  It has this nifty feature where it will cache the objects it creates and you could specify the scope of that caching&#8230;for example SingletonBehavior, or OnPerSessionBehavior.  That&#8217;s great but I couldn&#8217;t make it work, regardless of the configuration it would always return a brand new object every time.</p>
<p>So then I went and checked out StructureMap.  It&#8217;s a little more complex to get set up and I personally don&#8217;t think it&#8217;s registration DSL is as nice as NInject&#8217;s but it works.  It has a similar caching feature where you can specify an Instance Scope of Application, Session, Request, Thread, etc.  Same problem though, no matter how I configured it the caching was always at the Application level.  So every session in the app would get back the same objects&#8230;not very secure on the data front.</p>
<p>Now, I am completely open to the possibility that I don&#8217;t know enough about either of these tools and that the roadblocks I ran into were user error.  However, I realized I was spending way too much time on something that is essentially a very simple problem.  Here&#8217;s what I needed out of an IoC tool:</p>
<p>1. Constructor Injection &#8211; I don&#8217;t really care about property or method injection, just constructors<br />
2. Cache the Output at Session Level<br />
3. Easy Registration with Constructor Args</p>
<p>So the following is what I came up with to solve the problem:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> DI <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">internal</span> <span style="color: #FF0000;">class</span> InjectionBinder <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> Type Abstract <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> Type Concrete <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> CtorArgs <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// A lightweight dependency injection tool that supports constructor injection and HttpContext.Session caching.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> Injector <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> SessionBindingKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;__InjectorBindings__&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> SessionCacheKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;__InjectorCache__&quot;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> List<span style="color: #008000;">&lt;</span>InjectionBinder<span style="color: #008000;">&gt;</span> _bindings <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionBindingKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionBindingKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>InjectionBinder<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>List<span style="color: #008000;">&lt;</span>InjectionBinder<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionBindingKey<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionBindingKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> List<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span>Type, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;&gt;</span> _cache <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionCacheKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                    HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionCacheKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span>Type, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>List<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span>Type, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #000000;">&#41;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionCacheKey<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionCacheKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Returns a concrete instance of the specified abstract type using the provided bindings and </span>
        <span style="color: #008080; font-style: italic;">/// attempts to satisfy that type's constructor arguments.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;abstractType&quot;&gt;The abstract type of the object to initialize.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">object</span> GetInstance<span style="color: #000000;">&#40;</span>Type abstractType<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Return the item from the cache if it's in there</span>
            var cache <span style="color: #008000;">=</span> _cache.<span style="color: #0000FF;">ToDictionary</span><span style="color: #000000;">&#40;</span>o <span style="color: #008000;">=&gt;</span> o.<span style="color: #0000FF;">Key</span>, o <span style="color: #008000;">=&gt;</span> o.<span style="color: #0000FF;">Value</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>cache.<span style="color: #0000FF;">ContainsKey</span><span style="color: #000000;">&#40;</span>abstractType<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> cache<span style="color: #000000;">&#91;</span>abstractType<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// If the type is in the bindings, return the concrete</span>
            var foundBinding <span style="color: #008000;">=</span> _bindings.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>b <span style="color: #008000;">=&gt;</span> b.<span style="color: #0000FF;">Abstract</span> <span style="color: #008000;">==</span> abstractType<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>foundBinding <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span>foundBinding.<span style="color: #0000FF;">Concrete</span>, foundBinding.<span style="color: #0000FF;">CtorArgs</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #FF0000;">object</span> obj <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            var ctors <span style="color: #008000;">=</span> abstractType.<span style="color: #0000FF;">GetConstructors</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// If the type has no constructor, then just create one</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>ctors.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">return</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span>abstractType<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// If there are constructors, find one which takes arguments of the types we have binders for</span>
            ctors.<span style="color: #0600FF;">ForEach</span><span style="color: #000000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#123;</span>
                var prms <span style="color: #008000;">=</span> c.<span style="color: #0000FF;">GetParameters</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                var args <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                var haveBindings <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                prms.<span style="color: #0600FF;">ForEach</span><span style="color: #000000;">&#40;</span>p <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#123;</span>
                    var binding <span style="color: #008000;">=</span> _bindings.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>b <span style="color: #008000;">=&gt;</span> b.<span style="color: #0000FF;">Abstract</span> <span style="color: #008000;">==</span> p.<span style="color: #0000FF;">ParameterType</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>binding <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> haveBindings <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span> args.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span>binding.<span style="color: #0000FF;">Concrete</span>, binding.<span style="color: #0000FF;">CtorArgs</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>haveBindings<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> obj <span style="color: #008000;">=</span> Activator.<span style="color: #0000FF;">CreateInstance</span><span style="color: #000000;">&#40;</span>abstractType, args.<span style="color: #0000FF;">ToArray</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> obj<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Returns a concrete instance of the specified abstract type using the provided bindings and </span>
        <span style="color: #008080; font-style: italic;">/// attempts to satisfy that type's constructor arguments.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;typeparam name=&quot;TAbstract&quot;&gt;The abstract type of the object to initialize.&lt;/typeparam&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> TAbstract GetInstance<span style="color: #008000;">&lt;</span>TAbstract<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> where TAbstract <span style="color: #008000;">:</span> <span style="color: #FF0000;">class</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> GetInstance<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span> <span style="color: #000000;">&#40;</span>TAbstract<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> TAbstract<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Creates a binding rule between an abstract type and a concrete type.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;typeparam name=&quot;TAbstract&quot;&gt;The abstract type for the binding.&lt;/typeparam&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;typeparam name=&quot;TConcrete&quot;&gt;The concrete type for the binding&lt;/typeparam&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;ctorArgs&quot;&gt;The list of constructor arguments to use when initializing the instance of the concrete type.&lt;/param&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Bind<span style="color: #008000;">&lt;</span>TAbstract, TConcrete<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> ctorArgs<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            var binding <span style="color: #008000;">=</span> _bindings.<span style="color: #0000FF;">Find</span><span style="color: #000000;">&#40;</span>b <span style="color: #008000;">=&gt;</span> b.<span style="color: #0000FF;">Abstract</span> <span style="color: #008000;">==</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TAbstract<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>binding <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                binding.<span style="color: #0000FF;">Concrete</span> <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TConcrete<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                binding.<span style="color: #0000FF;">CtorArgs</span> <span style="color: #008000;">=</span> ctorArgs<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span> <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
                _bindings.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> InjectionBinder <span style="color: #000000;">&#123;</span>
                    Abstract <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TAbstract<span style="color: #000000;">&#41;</span>,
                    Concrete <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>TConcrete<span style="color: #000000;">&#41;</span>,
                    CtorArgs <span style="color: #008000;">=</span> ctorArgs
                <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Clears all Injector binding rules and empties the internal cache.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Kill<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionBindingKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
            HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Session</span><span style="color: #000000;">&#91;</span>SessionCacheKey<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And here&#8217;s how we register the bindings:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> BindInjectionContainer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    Injector.<span style="color: #0000FF;">Kill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Clears out previously created bindings and empties the cache</span>
&nbsp;
    var currentClient <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Client<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Doesn't matter...just an example</span>
    var currentUser <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> User<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    var currentCulture <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;en-US&quot;</span><span style="color: #008000;">;</span>
&nbsp;
    Injector.<span style="color: #0000FF;">Bind</span><span style="color: #008000;">&lt;</span>IClientRepository, ClientRepository<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> currentClient, currentCulture <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Injector.<span style="color: #0000FF;">Bind</span><span style="color: #008000;">&lt;</span>IUserRepository, UserRepository<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> currentClient, currentCulture, currentUser <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    Injector.<span style="color: #0000FF;">Bind</span><span style="color: #008000;">&lt;</span>ISecurityRepository, SecurityRepository<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And lastly, here&#8217;s how you request an object:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var secRepo <span style="color: #008000;">=</span> Injector.<span style="color: #0000FF;">GetInstance</span><span style="color: #008000;">&lt;</span>ISecurityRepository<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>So, it may be ridiculous to roll-your-own on the IoC container but as you can see it was pretty simple to get what I needed.  It&#8217;s very solution specific but what&#8217;s wrong with that.  In this instance it&#8217;s pretty easy to swap out for something more feature rich if necessary but for now&#8230;I call YAGNI on all that.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2009/04/24/ninject-vs-structuremap-vs-i-made-this/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>StackOverflow Love</title>
		<link>http://www.thegrubbsian.com/2008/12/17/stackoverflow-love/</link>
		<comments>http://www.thegrubbsian.com/2008/12/17/stackoverflow-love/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 21:31:34 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=106</guid>
		<description><![CDATA[I love stackoverflow.com! &#0160;It doesn&#39;t get much better than a bunch of geeks answering each others&#39; questions for merit badges]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://www.stackoverflow.com">stackoverflow.com</a>! &#0160;It doesn&#39;t get much better than a bunch of geeks answering each others&#39; questions for merit badges <img src='http://thegrubbsian.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/12/17/stackoverflow-love/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Echo-ORM</title>
		<link>http://www.thegrubbsian.com/2008/10/30/echo-orm/</link>
		<comments>http://www.thegrubbsian.com/2008/10/30/echo-orm/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 20:48:16 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=110</guid>
		<description><![CDATA[I think we&#39;ve all encountered the fear of open source software amongst some of our clients. &#0160;I like to call it ossphobia. &#0160;It basically amounts to a categorical rejection of anything that doesn&#39;t arrive in shrink wrap with a shiny holographic label displaying a Microsoft logo. &#0160;While I am primarily a Microsoft developer, I am [...]]]></description>
			<content:encoded><![CDATA[<p>I think we&#39;ve all encountered the fear of open source software amongst some of our clients. &#0160;I like to call it ossphobia. &#0160;It basically amounts to a categorical rejection of anything that doesn&#39;t arrive in shrink wrap with a shiny holographic label displaying a Microsoft logo. &#0160;While I am primarily a Microsoft developer, I am by no means a fanatic and often find that the best solution to a problem is exactly the opposite of the solution championed by Microsoft.</p>
<div>Recently I was working with one such ossphobic client on a reletively simple reporting application. &#0160;We were in need of a very simple ORM-lite solution (similar to what SubSonic provides) to store meta-data information in a database. &#0160;My first thought was, &quot;Well, why don&#39;t we just use SubSonic?&quot; &#0160;This was met with blank stares and a palatable sense of &quot;Oh no he didn&#39;t.&quot; hanging in the air. &#0160;So, after realizing that my chances of changing this client&#39;s mind on the subject of OSS was nigh impossible, I decided, &quot;The hell with it, if they don&#39;t want to use the inexpensive solution, I&#39;ll just write my own ORM and call it custom software.&quot;</div>
<p>
<div>Some of you (whoever <span style="text-decoration: underline;">you</span> are) will find the idea of rolling your own ORM in the age of NHibernate, LINQ to SQL, SubSonic, and etc. ridiculous. &#0160;&quot;There are so many good frameworks out there, why would you ever want to write your own?&quot; &#0160;Well, I&#39;ll give you a few reasons&#8230;you may not like them&#8230;but I do so you&#39;ll just have to deal.</div>
<p>
<div>
<ol>
<li>Full Control &#8211; One of the things that&#39;s great about SubSonic for example is that it just flat works out of the box. &#0160;You do some simple configuration, generate your objects, and your off and running. &#0160;Literally, 10 minutes. &#0160;The problem here is that much of the internals of SubSonic are kind of a black box. &#0160;The source code, while well written, can still be a pretty deep stack. &#0160;If I for example wanted to add a feature to SubSonic, I&#39;d find the learning curve pretty high. &#0160;A custom ORM designed specifically for simplicity offers a much lower barrier to extension.</li>
<li>The Right Tool for the Job &#8211; So in the specific case that prompted me to write my own framework, there were some specific features that we needed. &#0160;I was able to winnow down my concept to cover just what was needed at the time (the YAGNI principle). &#0160;This allowed my framework to be really targeted and the API that I exposed to consumers of the framework was extremely simple.&#0160;&#0160;</li>
<li>I Like Learning &#8211; I don&#39;t often get the chance to work on framework type projects so this gave me the opportunity to really try out some ideas in an environment that wasn&#39;t tied immediately to a project deliverable. &#0160;I think everyone should have a side project that takes them outside the path of their normal daily development&#8230;I have several such side endeavors.</li>
</ol>
<p>So, now that all that&#39;s been said. &#0160;I&#39;m introducing Echo ORM as an open source project on Google Code. &#0160;It&#39;s a very small framework and in a very alpha state, but I&#39;d love some feedback on the approach that I&#39;ve taken and I welcome comments or contributions.</div>
<p>
<div>Echo ORM: <a href="http://code.google.com/p/echo-orm">http://code.google.com/p/echo-orm</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/10/30/echo-orm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Excellent Post on Project Size</title>
		<link>http://www.thegrubbsian.com/2008/10/21/excellent-post-on-project-size/</link>
		<comments>http://www.thegrubbsian.com/2008/10/21/excellent-post-on-project-size/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 23:09:05 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=111</guid>
		<description><![CDATA[An excellent post on project size&#8230;as in how many people are on a project. http://semanticvector.blogspot.com/2008/10/more-programmers-more-code.html Personally, I&#39;ve always subscribed to the Amazon two pizza maxim. &#0160;Any project team should be able to eat comfortably on two large pizzas. &#0160;As soon as someone says, &#34;Say, I think we might need to order a third pie.&#34; &#0160;You [...]]]></description>
			<content:encoded><![CDATA[<p>An excellent post on project size&#8230;as in how many people are on a project.</p>
<p>
<div><a href="http://semanticvector.blogspot.com/2008/10/more-programmers-more-code.html">http://semanticvector.blogspot.com/2008/10/more-programmers-more-code.html</a></div>
<p>
<div>Personally, I&#39;ve always subscribed to the Amazon two pizza maxim. &#0160;Any project team should be able to eat comfortably on two large pizzas. &#0160;As soon as someone says, &quot;Say, I think we might need to order a third pie.&quot; &#0160;You know your project is too big and is likely going to suffer from hauling around the extra weight.</div>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/10/21/excellent-post-on-project-size/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wi-Fi Mile High</title>
		<link>http://www.thegrubbsian.com/2008/10/05/wi-fi-mile-high/</link>
		<comments>http://www.thegrubbsian.com/2008/10/05/wi-fi-mile-high/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 06:22:26 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=113</guid>
		<description><![CDATA[So, I&#8217;m on a plane right now and there are at least five people in my immediate vicinity working on laptops. Every single one of these people is reading email in Outlook. The obvious disgust at Outlook aside, this leads me to the question, &#8220;Why don&#8217;t we have Wi-Fi on every commercial flight yet?&#8221;. I [...]]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;m on a plane right now and there are at least five people in my immediate vicinity working on laptops.  Every single one of these people is reading email in Outlook.  The obvious disgust at Outlook aside, this leads me to the question, &#8220;Why don&#8217;t we have Wi-Fi on every commercial flight yet?&#8221;.</p>
<p>I myself would be incredibly attracted to any airline that offered this service.  It wouldn&#8217;t even have to be free.  I&#8217;d happily pay an extra $10 for my ticket if it came with even modestly quick Internet access.</p>
<p>I doubt if any airline execs read this particular blog, but if you are&#8230;Wi-Fi&#8230;all I have to say&#8230;Wi-Fi.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/10/05/wi-fi-mile-high/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Should We Hold a Funeral for IE6?</title>
		<link>http://www.thegrubbsian.com/2008/09/29/should-we-hold-a-funeral-for-ie6/</link>
		<comments>http://www.thegrubbsian.com/2008/09/29/should-we-hold-a-funeral-for-ie6/#comments</comments>
		<pubDate>Mon, 29 Sep 2008 22:27:16 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=116</guid>
		<description><![CDATA[Folks, I think the time is nearing&#8230;may it come quickly. &#160;I just loaded up IE8 beta 2 in a VM and I just realized that by the time IE8 is released, IE6 will be 8 years old and two whole versions behind. &#160;The thought of trying to write rich-Internet applications for a browser that was [...]]]></description>
			<content:encoded><![CDATA[<p>Folks, I think the time is nearing&#8230;may it come quickly. &#160;I just loaded up IE8 beta 2 in a VM and I just realized that by the time IE8 is released, IE6 will be 8 years old and two whole versions behind. &#160;The thought of trying to write rich-Internet applications for a browser that was released in mid-2001 is becoming more and more frightening. &#160;</p>
<p>
<div>In my line of work the most compelling reason to continue support for IE6 is that most large companies still deploy it to the desktops. &#160;A surprising number even block the upgrade to IE7 forcing thier users to suffer with a slow and broken browser. &#160;That aside, is it time to start turning away work (or at least seriously discouraging work) if the client insists on supporting IE6? &#160;In my opinion, we&#39;re almost there. &#160;</div>
<p>
<div>In fact I think it&#39;s the only way that change is going to happen. &#160;Companies usually don&#39;t make major shifts like this without it hitting them in the pocketbooks. &#160;If suddenly a larger and larger portion of vendors and line-of-business apps stop supporting IE6 they will feel the pain and suddenly see the light. &#160;So don&#39;t be afraid to question your next client or project when the subject of IE6 support comes up&#8230;and don&#39;t be afraid to say no&#8230;say no to IE6.</div>
<p>
<div>Join the Movement:&#160;<a href="http://www.savethedevelopers.org/">http://www.savethedevelopers.org/</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/09/29/should-we-hold-a-funeral-for-ie6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Urgent!</title>
		<link>http://www.thegrubbsian.com/2008/09/20/urgent/</link>
		<comments>http://www.thegrubbsian.com/2008/09/20/urgent/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 05:26:44 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=117</guid>
		<description><![CDATA[An interesting experiment going on over at 37 Signals: http://www.37signals.com/svn/posts/966-urgency-is-poisonous.&#160; I think they might be on to something.&#160; I know that my current project would have benefited greatly from this kind of freedom from urgency.&#160; I can attest first hand that extreme urgency does not elicit the best code or the best mental attitudes from [...]]]></description>
			<content:encoded><![CDATA[<p>An interesting experiment going on over at 37 Signals: <a href="http://www.37signals.com/svn/posts/966-urgency-is-poisonous">http://www.37signals.com/svn/posts/966-urgency-is-poisonous</a>.&#160; I think they might be on to something.&#160; I know that my current project would have benefited greatly from this kind of freedom from urgency.&#160; I can attest first hand that extreme urgency does not elicit the best code or the best mental attitudes from a team.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/09/20/urgent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Access Modifiers and Programmer (mis)Trust</title>
		<link>http://www.thegrubbsian.com/2008/09/17/access-modifiers-and-programmer-mistrust/</link>
		<comments>http://www.thegrubbsian.com/2008/09/17/access-modifiers-and-programmer-mistrust/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 23:36:23 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=118</guid>
		<description><![CDATA[So I&#39;ve been looking at some new languages recently, particularly dynamic languages like Ruby and Python.&#160; One of the first things I noticed about their syntax was the lack of access modifiers.&#160; I suppose the assumption could be made that since C# is type-enforced that it lends itself to access modifiers but I also wonder [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#39;ve been looking at some new languages recently, particularly dynamic languages like Ruby and Python.&#160; One of the first things I noticed about their syntax was the lack of access modifiers.&#160; I suppose the assumption could be made that since C# is type-enforced that it lends itself to access modifiers but I also wonder if maybe it&#39;s just a case of programmer mistrust.</p>
<p>If I&#39;m writing an API that&#39;s going to be consumed by other developers, am I really so paranoid that I need to lock things away into isolated boxes to prevent misuse?&#160; No, I think I fairly well trust consumers of my code to understand my code prior to using it or do so at thier own peril.</p>
<p>I can see the argument being made that it makes the API cleaner if implementation code is hidden from the consumer.&#160; I don&#39;t disagree, but I think that problem is better solved by encapsulating implementation logic into a lower level class.&#160; This has the added benefit of making the implementation available for anyone that wants to take a look under the covers, but still providing a clean API layer.</p>
<p>So what am I really proposing here?&#160; Should we just mark everything public everywhere?&#160; No, I don&#39;t think that&#39;s really what I&#39;m saying.&#160; What I am saying, is that it&#39;s interesting that a number of dynamic languages have decided to trust thier developers more than C# and I just think that&#39;s interesting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/09/17/access-modifiers-and-programmer-mistrust/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google Chrome: Friend or Foe</title>
		<link>http://www.thegrubbsian.com/2008/09/02/google-chrome-friend-or-foe/</link>
		<comments>http://www.thegrubbsian.com/2008/09/02/google-chrome-friend-or-foe/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 17:26:54 +0000</pubDate>
		<dc:creator>JC Grubbs</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.thegrubbsian.com/?p=120</guid>
		<description><![CDATA[The jury is still out on Google Chrome&#8230;most likely since no one has really been able to get their hands on it yet.&#160; The browser is set to ship in beta sometime today.&#160; But even before its release the very idea of a new browser begs the question&#8230; &#34;Do we need another browser?&#34; Like most [...]]]></description>
			<content:encoded><![CDATA[<p>The jury is still out on Google Chrome&#8230;most likely since no one has really been able to get their hands on it yet.&nbsp; The browser is set to ship in beta sometime today.&nbsp; But even before its release the very idea of a new browser begs the question&#8230; &quot;Do we need another browser?&quot;</p>
<p>Like most philosophical questions of this depth (mind you not very deep at all) the answer is varied.&nbsp; Some say, &quot;Yes, more browsers equals more choice equals more competition equals better features, blah blah balh.&quot;&nbsp; Others say, &quot;Are you crazy?&nbsp; I just got over IE6!&quot;&nbsp; In my opinion, it&#8217;s not really about the browser it&#8217;s about the engines.&nbsp; </p>
<p>I don&#8217;t care if the title bar of my browser says Microsoft, is a drab 1940&#8242;s post-ware gray (ala Safari), or has a little curled up fox gently engulfing the globe.&nbsp; What I do care about is how the thing works.&nbsp; As a developer, I crave consistency.&nbsp; When I write a piece of code I want it to function precisely as I expect it to, and I want it to do that in every environment that calls it.&nbsp; In this vein the nice thing about Google Chrome is that it&#8217;s built with open source pieces&#8230;it&#8217;s the Frankenstein of browsers really.&nbsp; It has WebKit&#8217;s rendering engine, parts of the plug-in architecture are ripped off from FireFox, and I suspect that a its new JavaScript engine is built on concepts from a whole realm of different open source projects.</p>
<p>So, we&#8217;ll have to wait and see what comes of it.&nbsp; If it runs Firebug, and is really as fast as they say, then it&#8217;ll probably be a good browser for developers, if not it will just be another &quot;Oh that&#8217;s kinda cool&quot;, and then we&#8217;ll all go back to FireFox.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thegrubbsian.com/2008/09/02/google-chrome-friend-or-foe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
