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)); }
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)); }
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; } }
public TComponent TryResolve <TComponent>() { TComponent instance; return(container.TryResolve(out instance) ? instance : default(TComponent)); }
public static bool TryResolve <TService>(out TService service) { ThrowIfNotInitialized(); return(_container.TryResolve <TService>(out service)); }
public override bool TryResolve(Type serviceType, out object instance) { return(_container.TryResolve(serviceType, out instance)); }
public bool TryResolve(Type type, object data, out object value) { return(_container.TryResolve(type, out value)); }