Exemple #1
0
        private void AttachToElement(FrameworkElement element, IEnumerable <IUIServiceFactory> serviceList)
        {
            if (isFullyAttached)
            {
                return;
            }

            log.DebugFormat(FrameworkElementFormatter.GetInstance(), "Attaching service list for {0}", element);
            this.element = element;
            foreach (var serviceFactory in serviceList)
            {
                var service     = serviceFactory.CreateUIService();
                var serviceType = service.GetType();
                var customAttrs = serviceType.GetCustomAttributes(typeof(ImplementedServiceAttribute), true);
                if (customAttrs != null && customAttrs.Count() > 0)
                {
                    foreach (ImplementedServiceAttribute customAttr in customAttrs)
                    {
                        serviceType = customAttr.ImplementedServiceType;
                        AddServiceAs(serviceType, service);
                    }
                }
                else
                {
                    AddServiceAs(serviceType, service);
                }
            }
            LoadedEventManager.AddListener(element, this);
            UnloadedEventManager.AddListener(element, this);
            if (element.IsLoaded)
            {
                Element_Loaded(element, new RoutedEventArgs());
            }
        }
Exemple #2
0
 public void Dispose()
 {
     log.DebugFormat(FrameworkElementFormatter.GetInstance(), "Detaching service provider from {0}", element);
     if (owningWindow != null)
     {
         owningWindow.Closed -= OwningWindow_Closed;
     }
     LoadedEventManager.RemoveListener(element, this);
     UnloadedEventManager.RemoveListener(element, this);
     DetachFromElement(element, serviceImplementations.Values);
     foreach (var service in serviceImplementations.Values)
     {
         service.Dispose();
     }
 }