private void findAndAddViewModelInstances() { this.IsBusy = true; this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): entered"); Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly currentAssembly in assemblies) { if (currentAssembly.FullName.Contains("System.Runtime")) { this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): skipped Assembly '{currentAssembly.FullName}'"); } else { foreach (Type currentType in currentAssembly.GetTypes()) { try { foreach (object customAttribute in currentType.GetCustomAttributes(true)) { try { LocatorAttribute locatorAttribute = customAttribute as LocatorAttribute; if (locatorAttribute != null) { if (!this.registeredInstances.ContainsKey(locatorAttribute.Name)) { this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): adding new instance '{locatorAttribute.Name}'"); object instance = DiManager.GetInstance().Resolve(currentType); //TODO: just add type, let resolving be done by using app this.registeredInstances.Add(locatorAttribute.Name, instance); } else { this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): skipping '{locatorAttribute.Name}' as already registered"); } } } catch (Exception ex) { this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): Exception caught with Attributes: '{ex.Message}'", Contracts.Logger.Enums.LogLevel.Warning); } } } catch (Exception ex) { this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): Exception caught with Types: '{ex.Message}'", Contracts.Logger.Enums.LogLevel.Warning); } } } } this.logger?.Log($"ViewModelLocator.findAndAddViewModelInstances(): exited"); this.IsBusy = false; }
private void CreateContext(FieldInfo viElement, ref VIElement instance) { instance.Context.Add(Context); var frameAttr = FrameAttribute.GetFrame(viElement); if (frameAttr != null) { instance.Context.Add(ContextType.Frame, frameAttr); } var locatorAttr = LocatorAttribute.GetLocator(viElement) ?? LocatorAttribute.GetLocatorFomFindsBy(viElement); if (locatorAttr != null) { instance.Locator = locatorAttr; } if (_locator != null) { instance.Context.Add((this is Frame) ? ContextType.Frame : ContextType.Locator, _locator); } }