/// <summary> /// Gets or creates the <see cref="KeyedNavigationSource"/> with the default key. A <see cref="NavigationSourceContainer"/> is created if the <see cref="AllNavigationSources"/> collection does not contain the source name. /// </summary> /// <param name="sourceName">The source name</param> /// <returns>The navigation source</returns> public static NavigationSource CreateDefaultNavigationSource(string sourceName) { if (sourceName == null) { throw new ArgumentNullException(nameof(sourceName)); } if (allNavigationSources.TryGetValue(sourceName, out NavigationSourceContainer navigationSourceContainer)) { var navigationSource = navigationSourceContainer.NavigationSources.FirstOrDefault(n => n is KeyedNavigationSource && ((KeyedNavigationSource)n).Key == DefaultKeyedNavigationSourceKey); if (navigationSource != null) { throw new InvalidOperationException("The navigation source is already created"); } else { var defaultNavigationSource = new KeyedNavigationSource(DefaultKeyedNavigationSourceKey); navigationSourceContainer.Register(defaultNavigationSource); allNavigationSources[sourceName] = navigationSourceContainer; return(defaultNavigationSource); } } else { navigationSourceContainer = new NavigationSourceContainer(); var defaultNavigationSource = new KeyedNavigationSource(DefaultKeyedNavigationSourceKey); navigationSourceContainer.Register(defaultNavigationSource); allNavigationSources[sourceName] = navigationSourceContainer; return(defaultNavigationSource); } }
/// <summary> /// Adds the <see cref="NavigationSource"/>. The <see cref="NavigationSourceContainer"/> is created if the <see cref="AllNavigationSources"/> does not contain the source name. /// </summary> /// <param name="sourceName">The source name</param> /// <param name="navigationSource">The navigation source</param> public static void AddNavigationSource(string sourceName, NavigationSource navigationSource) { if (sourceName == null) { throw new ArgumentNullException(nameof(sourceName)); } if (navigationSource == null) { throw new ArgumentNullException(nameof(navigationSource)); } if (allNavigationSources.TryGetValue(sourceName, out NavigationSourceContainer navigationSourceContainer)) { navigationSourceContainer.Register(navigationSource); } else { navigationSourceContainer = new NavigationSourceContainer(); navigationSourceContainer.Register(navigationSource); allNavigationSources[sourceName] = navigationSourceContainer; } }