public Type ResolveImplementation(Type baseType)
        {
            Type resolvedType = decoratedResolver.ResolveImplementation(baseType);

            stallObject.WaitOne();
            return(resolvedType);
        }
コード例 #2
0
        private object Instantiate(Type type, string identifier, params object[] args)
        {
            if (implementationTypes[type] != null)
            {
                return(Instantiate((Type)implementationTypes[type], identifier, args));
            }
            if (type.IsInterface)
            {
                implementationTypes[type] = implementationResolver.ResolveImplementation(type);
                return(Instantiate((Type)implementationTypes[type], identifier, args));
            }

            ArrayList       arguments   = new ArrayList();
            ConstructorInfo constructor = constructorSelectionStrategy.GetConstructor(type);

            if (constructor == null)
            {
                throw new Exception("Unable to select constructor for Type " + type.FullName);
            }

            int paramCount = 0;

            foreach (ParameterInfo parameter in constructor.GetParameters())
            {
                if (paramCount < args.Length)
                {
                    arguments.Add(args[paramCount]);
                }
                else
                {
                    try
                    {
                        Type dependencyType = OverrideWithSpecifiedDependencyImplementationIfNecessary(type, parameter.ParameterType, identifier);
                        arguments.Add(GiveObjectByType(dependencyType, identifier));
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Failed to instantiate Type " + type.FullName, e);
                    }
                }
                paramCount++;
            }

            try
            {
                return(constructor.Invoke((object[])arguments.ToArray(typeof(object))));
            }
            catch (Exception e)
            {
                string message = "Unable to instante " + type.FullName + " using the following args: ";
                foreach (object arg in arguments)
                {
                    message += arg.ToString();
                    message += ", ";
                }
                throw new Exception(message, e);
            }
        }
コード例 #3
0
        private Type AllowOneThreadPerAppDomainToDoResolution(Type baseType)
        {
            Type resolvedType;

            lock (baseType)
            {
                resolvedType = resolvedTypeCache[baseType];
                if (resolvedType == null)
                {
                    resolvedType = decoratoredResolver.ResolveImplementation(baseType);
                    resolvedTypeCache[baseType] = resolvedType;
                }
            }
            return(resolvedType);
        }
 public void runResolution()
 {
     implementationType = implementationResolver.ResolveImplementation(typeToResolve);
 }