Exemplo n.º 1
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.º 2
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.º 3
0
        private static void AutoHookedUpViewModelChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(dependencyObject))
            {
                return;
            }

            string viewTypeName      = dependencyObject.GetType().FullName;
            string viewModelTypeName = viewTypeName.Replace(".Views.", ".ViewModels.") + "Model";

            Type viewModelType = Type.GetType(viewModelTypeName);

            if (viewModelType == null)
            {
                return;
            }


            //object viewModel = Activator.CreateInstance(viewModelType);

            //_iocRegistry.Register(viewModelType);
            //object viewModel = _iocRegistry.RegisteredEntry(viewModelType);

            object viewModel = null;

            if (!_iocRegistry.TryResolve(viewModelType, out viewModel))
            {
                return;
            }


            // view-viewModel hook up
            FrameworkElement view = dependencyObject as FrameworkElement;

            if (view != null)
            {
                view.DataContext = viewModel;
            }
        }
Exemplo n.º 4
0
        public TComponent TryResolve <TComponent>()
        {
            TComponent instance;

            return(container.TryResolve(out instance) ? instance : default(TComponent));
        }
Exemplo n.º 5
0
 public static bool TryResolve <TService>(out TService service)
 {
     ThrowIfNotInitialized();
     return(_container.TryResolve <TService>(out service));
 }
Exemplo n.º 6
0
 public override bool TryResolve(Type serviceType, out object instance)
 {
     return(_container.TryResolve(serviceType, out instance));
 }
Exemplo n.º 7
0
 public bool TryResolve(Type type, object data, out object value)
 {
     return(_container.TryResolve(type, out value));
 }