private object GetInstance()
        {
            if (String.IsNullOrWhiteSpace(_targetType))
            {
                return(null);
            }

            Type viewModelType = Type.GetType(_targetType);

            if (viewModelType == null)
            {
                return(null);
            }


            string tokenString = _isInDesignMode ? _designModeToken : _runTimeToken;
            object viewModel   = null;

            if (tokenString != null)
            {
                _iocRegistry.TryResolveNamed(tokenString, viewModelType, out viewModel);
            }
            else
            {
                _iocRegistry.TryResolveKeyed(_isInDesignMode ? OperatingMode.DesignMode : OperatingMode.RunTimeMode, viewModelType, out viewModel);
            }

            return(viewModel);
        }
Exemplo n.º 2
0
        protected override object GetInstance(Type service, string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                if (Container.TryResolve(service, out object instance))
                {
                    return(instance);
                }
            }
            else
            {
                if (Container.TryResolveNamed(key, service, out object instance))
                {
                    return(instance);
                }
            }

            return(base.GetInstance(service, key));
        }
Exemplo n.º 3
0
 protected override object GetInstance(Type service, string key)
 {
     if (string.IsNullOrWhiteSpace(key))
     {
         object result;
         if (container.TryResolve(service, out result))
         {
             return(result);
         }
     }
     else
     {
         object result;
         if (container.TryResolveNamed(key, service, out result))
         {
             return(result);
         }
     }
     throw new Exception(string.Format("Could not locate any instances of contract {0}.", key ?? service.Name));
 }
Exemplo n.º 4
0
 public override bool TryResolveNamed(string serviceName, Type serviceType, out object instance)
 {
     return(_container.TryResolveNamed(serviceName, serviceType, out instance));
 }