/// <summary> /// Initializes the specified service locator. /// </summary> /// <param name="serviceLocator">The service locator.</param> public void Initialize(IServiceLocator serviceLocator) { Argument.IsNotNull(() => serviceLocator); serviceLocator.RegisterTypeIfNotYetRegistered <ICommandManager, CommandManager>(); serviceLocator.RegisterTypeIfNotYetRegistered <IViewLoadManager, ViewLoadManager>(); serviceLocator.RegisterTypeIfNotYetRegistered <IViewModelWrapperService, ViewModelWrapperService>(); serviceLocator.RegisterTypeIfNotYetRegistered <IViewManager, ViewManager>(); serviceLocator.RegisterTypeIfNotYetRegistered <IViewModelManager, ViewModelManager>(); serviceLocator.RegisterTypeIfNotYetRegistered <IAutoCompletionService, AutoCompletionService>(); #if !XAMARIN && !WIN80 serviceLocator.RegisterTypeIfNotYetRegistered <IInteractivityManager, InteractivityManager>(); #endif ViewModelServiceHelper.RegisterDefaultViewModelServices(serviceLocator); // Don't use property, we cannot trust the cached property here yet in Visual Studio if (CatelEnvironment.GetIsInDesignMode()) { foreach (var assembly in AssemblyHelper.GetLoadedAssemblies()) { var attributes = assembly.GetCustomAttributesEx(typeof(DesignTimeCodeAttribute)); foreach (var attribute in attributes) { // No need to do anything } } } }
/// <summary> /// Initializes the designer options. /// </summary> public static void InitializeDesignTime() { if (CatelEnvironment.GetIsInDesignMode(false)) { lock (_lock) { var loadedAssemblies = AssemblyHelper.GetLoadedAssemblies(); if (loadedAssemblies.Count != _lastLoadedAssembliesCount) { _lastLoadedAssembliesCount = loadedAssemblies.Count; foreach (var assembly in loadedAssemblies) { // Part 1: support attributes try { var attributes = assembly.GetCustomAttributesEx(typeof(DesignTimeCodeAttribute)); foreach (var attribute in attributes) { // No need to do anything } } catch (Exception) { // Never kill the designer } // Part 2: support types deriving from custom attributes var initializerTypes = assembly.GetAllTypesSafely().Where(x => typeof(DesignTimeInitializer).IsAssignableFromEx(x)); foreach (var initializerType in initializerTypes) { try { // Note: instantiating is sufficient var initializer = (DesignTimeInitializer)Activator.CreateInstance(initializerType); } catch (Exception) { // Never kill the designer } } } } } } }