Beispiel #1
0
        /// <inheritdoc />
        public IController CreateInstance(Type type, IDictionary <string, object> arguments = null)
        {
            Type candidate = type;

            if (_container.CanResolve(candidate, arguments))
            {
                return((IController)_container.Resolve(candidate, arguments));
            }

            if ((type.IsGenericType) && (_container.CanResolve(candidate = type.GetGenericTypeDefinition(), arguments)))
            {
                return((IController)_container.Resolve(candidate, arguments));
            }

            candidate = type.GetInterfaces()
                        .Where(@interface => typeof(IController).IsAssignableFrom(@interface))
                        .OrderByDescending(@interface => @interface.GetGenericArguments().Length)
                        .First();
            return((IController)_container.Resolve(candidate, arguments));
        }