Activator performance improvement

Shouldn't close the previous PR early. Turns out I did not have to change much of my design.

Pinging previous trackers
@pranavkm
@halter73 
@rynowak
@ipjohnson
@yishaigalatzer 
Di should throw the missing dependency exception rather than the type activator

-----Original Message-----
From: "Ian Johnson" <notifications@github.com>
Sent: ‎10/‎3/‎2014 12:39 PM
To: "aspnet/DependencyInjection" <DependencyInjection@noreply.github.com>
Cc: "Yishai Galatzer" <yishai_galatzer@yahoo.com>
Subject: Re: [DependencyInjection] Activator performance improvement (#114)

In src/Microsoft.Framework.DependencyInjection/TypeActivator.cs:
> +                    if (mappedIndex >= 0)
> +                    {
> +                        // get it from args
> +                        // note that the method that we build is
> +                        // technically null safe against null value for the second parameter (of type object[])
> +                        // since in that case all mapped index would have stayed as -1 when the builder is created
> +                        // and this clause is never called
> +                        selected = Expression.ArrayIndex(createArgsParam, Expression.Constant(mappedIndex));
> +                    }
> +                    else
> +                    {
> +                        // get it from service provider
> +                        var constructorParamType = Expression.Constant(_constructorParamTypes[i]);
> +                        // should this value be cached?
> +                        var getServiceMethod = typeof(IServiceProvider).GetTypeInfo().GetDeclaredMethod("GetService");
> +                        selected = Expression.Call(serviceProviderParam, getServiceMethod, constructorParamType);
You probably want to handle the case where you get a null back from the service provider and throw an exception. In the old code it threw an general Exception but it might be nice to have a specific "MissingDependencyException" that holds a reference to the type being searched for and what type was being constructed. 
—
Reply to this email directly or view it on GitHub.=