private IFactoryConfiguration GetFactoryConfiguration(string name, IContainer container)
        {
            IFactoryConfiguration factoryConfig = container.Configuration.GetFactoryConfiguration(name);
            if (factoryConfig == null)
            {
                factoryConfig = new FactoryConfiguration();
                factoryConfig.Name = name;
                container.Configuration.AddFactoryConfiguration(factoryConfig);
            }

            return factoryConfig;
        }
        private MethodInfo MatchMethods(FactoryConfiguration factory, Type type, string methodName, bool isStatic)
        {
            MethodInfo[] methods = type.GetMethods();
            MethodInfo bestMethodMatch = null;
            int bestScore = int.MaxValue;

            foreach (MethodInfo method in methods)
            {
                if (method.Name != methodName)
                    continue;

                int score = 0;
                ParameterInfo[] parameters = method.GetParameters();

                //if param count doesnt match , move to next ctor
                if (parameters.Length != factory.ParameterConfigurations.Count)
                    continue;

                if (parameters.Length == 0)
                    return method;

                #region Match parameters

                for (int i = 0; i < parameters.Length; i++)
                {
                    ParameterConfiguration parameterConfig = (ParameterConfiguration) factory.ParameterConfigurations[i];
                    Type type1 = parameters[i].ParameterType;
                    Type type2 = parameterConfig.Type;
                    if (type2 == null)
                    {
                        //untyped parameter
                        try
                        {
                            ValueConfiguration parameterValueConfig = (ValueConfiguration) parameterConfig.Value;
                            object res = Convert.ChangeType(parameterValueConfig.Value, type1);
                        }
                        catch
                        {
                            continue;
                        }
                        score ++;
                    }
                    else
                    {
                        //typed parameter

                        if (type1.IsAssignableFrom(type2))
                        {
                            if (type1 == type2)
                            {
                                //same type
                                score ++;
                            }
                            else if (type2.IsSubclassOf(type1))
                            {
                                //subclass
                                Type tmpType = type2;
                                while (tmpType != type1)
                                {
                                    score++;
                                    tmpType = tmpType.BaseType;
                                }
                            }
                            else
                            {
                                //interface
                                score ++;
                            }
                        }
                        else
                        {
                            //ignore this
                            continue;
                        }
                    }
                }

                #endregion

                if (score < bestScore && score != 0)
                {
                    bestMethodMatch = method;
                    bestScore = score;
                }
            }
            return bestMethodMatch;
        }
 private void FillFactoryParameterTypes(FactoryConfiguration factoryConfig)
 {
     foreach (ParameterConfiguration parameter in factoryConfig.ParameterConfigurations)
     {
         if (parameter.Value is ObjectConfiguration)
         {
             ObjectConfiguration referenceObject = parameter.Value as ObjectConfiguration;
             parameter.Type = referenceObject.Type;
         }
     }
 }