Improvement in ResolveImpl

Developer
Feb 14, 2009 at 10:40 PM

If the reuseScope is Hierarchy, don't recursively call ResolveImpl, just call CreateInstance on the entry.Container as shown below"

 

 

case ReuseScope.Hierarchy:
if (entry.Instance == null)
{
    if (entry.Container != this)
        // Matt Changed
        //return entry.Container.ResolveImpl<TService, TFunc>(name, invoker, throwIfMissing);
        return entry.Container.CreateInstance<TService, TFunc>(entry, invoker);
    
else 
        entry.Instance = CreateInstance<TService, TFunc>(entry, invoker);
}

 

Feb 15, 2009 at 10:01 AM
Edited Feb 27, 2009 at 4:19 AM
Nice one mate! One less recursive call would help performance a bit.

Am I alone in that I'd ditch the "else" after the "return"? I know it doesn't really matter one way or the other, but I don't see the point in keeping an "else" around when the previous statement exits from the method anyway.
Developer
Feb 16, 2009 at 9:03 AM
You are correct.  I noticed this yesterday as well, but haven't tried it.  I'll make the change on my copy and run the tests.
Developer
Feb 16, 2009 at 9:15 AM

I have confirmed that this can be simplified even more by

 

 

case ReuseScope.Hierarchy:
    if (entry.Instance == null)
    {
        entry.Instance = entry.Container.CreateInstance<TService, TFunc>(entry, invoker);
    }
    return (TService)entry.Instance;
 

 

Coordinator
Feb 26, 2009 at 1:47 PM
Awesome folks!

Just checked-in dennis proposed changes :)

For some reason, I didn't have notifications turned on for discussions, so sorry for the delay!