Skip to content

Commit

Permalink
add ModuleInfo collection to IModuleManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Aug 24, 2020
1 parent 5a06d41 commit 413ca57
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Forms/Prism.Forms/Modularity/IModuleCatalogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, Initializ
where T : IModule =>
catalog.AddModule<T>(typeof(T).Name, mode);

/// <summary>
/// Adds the module.
/// </summary>
/// <returns>The module.</returns>
/// <param name="catalog">Catalog.</param>
/// <param name="name">Name.</param>
/// <typeparam name="T">The <see cref="IModule"/> type parameter.</typeparam>
public static IModuleCatalog AddModule<T>(this IModuleCatalog catalog, string name)
where T : IModule =>
catalog.AddModule<T>(name, InitializationMode.WhenAvailable);
Expand Down
7 changes: 6 additions & 1 deletion src/Forms/Prism.Forms/Modularity/ModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class ModuleManager : IModuleManager
/// </summary>
protected IModuleCatalog ModuleCatalog { get; }

/// <summary>
/// Gets all the <see cref="IModuleInfo"/> classes that are in the <see cref="IModuleCatalog"/>.
/// </summary>
public IEnumerable<IModuleInfo> Modules => ModuleCatalog.Modules;

/// <summary>
/// Raised when a module is loaded or fails to load.
/// </summary>
Expand Down Expand Up @@ -56,7 +61,7 @@ public void Run()
}

/// <summary>
/// Loads and initializes the module in the <see cref="ModuleCatalog"/> with the name <paramref name="moduleName"/>.
/// Loads and initializes the module in the <see cref="IModuleCatalog"/> with the name <paramref name="moduleName"/>.
/// </summary>
/// <param name="moduleName">Name of the module requested for initialization.</param>
public void LoadModule(string moduleName)
Expand Down
19 changes: 19 additions & 0 deletions src/Prism.Core/Modularity/IModuleCatalogCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ public static bool Exists<T>(this IModuleCatalog catalog)
public static bool Exists(this IModuleCatalog catalog, string name) =>
catalog.Modules.Any(module => module.ModuleName == name);

/// <summary>
/// Gets the current <see cref="ModuleState"/> of the <see cref="IModule"/>.
/// </summary>
/// <typeparam name="T">The <see cref="IModule"/> to check.</typeparam>
/// <param name="catalog">Catalog.</param>
/// <returns></returns>
public static ModuleState GetModuleState<T>(this IModuleCatalog catalog)
where T : IModule =>
catalog.Modules.FirstOrDefault(mi => mi.ModuleType == typeof(T).AssemblyQualifiedName).State;

/// <summary>
/// Gets the current <see cref="ModuleState"/> of the <see cref="IModule"/>.
/// </summary>
/// <param name="catalog">Catalog.</param>
/// <param name="name">Name.</param>
/// <returns></returns>
public static ModuleState GetModuleState(this IModuleCatalog catalog, string name) =>
catalog.Modules.FirstOrDefault(module => module.ModuleName == name).State;

/// <summary>
/// Checks to see if the <see cref="IModule"/> is already initialized.
/// </summary>
Expand Down
8 changes: 6 additions & 2 deletions src/Prism.Core/Modularity/IModuleManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


using System;
using System.Collections.Generic;

namespace Prism.Modularity
{
Expand All @@ -9,6 +8,11 @@ namespace Prism.Modularity
/// </summary>
public interface IModuleManager
{
/// <summary>
/// Gets all the <see cref="IModuleInfo"/> classes that are in the <see cref="IModuleCatalog"/>.
/// </summary>
IEnumerable<IModuleInfo> Modules { get; }

/// <summary>
/// Initializes the modules marked as <see cref="InitializationMode.WhenAvailable"/> on the <see cref="IModuleCatalog"/>.
/// </summary>
Expand Down
76 changes: 76 additions & 0 deletions src/Prism.Core/Modularity/IModuleManagerExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System.Linq;

namespace Prism.Modularity
{
/// <summary>
/// Common extensions for the <see cref="IModuleManager"/>
/// </summary>
public static class IModuleManagerExtensions
{
/// <summary>
/// Checks to see if the <see cref="IModule"/> exists in the <see cref="IModuleCatalog.Modules"/>
/// </summary>
/// <returns><c>true</c> if the Module exists.</returns>
/// <param name="manager">The <see cref="IModuleManager"/>.</param>
/// <typeparam name="T">The <see cref="IModule"/> to check for.</typeparam>
public static bool ModuleExists<T>(this IModuleManager manager)
where T : IModule =>
manager.Modules.Any(mi => mi.ModuleType == typeof(T).AssemblyQualifiedName);

/// <summary>
/// Exists the specified catalog and name.
/// </summary>
/// <returns><c>true</c> if the Module exists.</returns>
/// <param name="catalog">Catalog.</param>
/// <param name="name">Name.</param>
public static bool ModuleExists(this IModuleManager catalog, string name) =>
catalog.Modules.Any(module => module.ModuleName == name);

/// <summary>
/// Gets the current <see cref="ModuleState"/> of the <see cref="IModule"/>.
/// </summary>
/// <typeparam name="T">The <see cref="IModule"/> to check.</typeparam>
/// <param name="manager">The <see cref="IModuleManager"/>.</param>
/// <returns></returns>
public static ModuleState GetModuleState<T>(this IModuleManager manager)
where T : IModule =>
manager.Modules.FirstOrDefault(mi => mi.ModuleType == typeof(T).AssemblyQualifiedName).State;

/// <summary>
/// Gets the current <see cref="ModuleState"/> of the <see cref="IModule"/>.
/// </summary>
/// <param name="manager">The <see cref="IModuleManager"/>.</param>
/// <param name="name">Name.</param>
/// <returns></returns>
public static ModuleState GetModuleState(this IModuleManager manager, string name) =>
manager.Modules.FirstOrDefault(module => module.ModuleName == name).State;

/// <summary>
/// Checks to see if the <see cref="IModule"/> is already initialized.
/// </summary>
/// <returns><c>true</c>, if initialized, <c>false</c> otherwise.</returns>
/// <param name="manager">The <see cref="IModuleManager"/>.</param>
/// <typeparam name="T">The <see cref="IModule"/> to check.</typeparam>
public static bool IsModuleInitialized<T>(this IModuleManager manager)
where T : IModule =>
manager.Modules.FirstOrDefault(mi => mi.ModuleType == typeof(T).AssemblyQualifiedName)?.State == ModuleState.Initialized;

/// <summary>
/// Checks to see if the <see cref="IModule"/> is already initialized.
/// </summary>
/// <returns><c>true</c>, if initialized, <c>false</c> otherwise.</returns>
/// <param name="manager">The <see cref="IModuleManager"/>.</param>
/// <param name="name">Name.</param>
public static bool IsModuleInitialized(this IModuleManager manager, string name) =>
manager.Modules.FirstOrDefault(module => module.ModuleName == name)?.State == ModuleState.Initialized;

/// <summary>
/// Loads and initializes the module in the <see cref="IModuleCatalog"/>.
/// </summary>
/// <typeparam name="T">The <see cref="IModule"/> to load.</typeparam>
/// <param name="manager">The <see cref="IModuleManager"/>.</param>
public static void LoadModule<T>(this IModuleManager manager)
where T : IModule =>
manager.LoadModule(typeof(T).Name);
}
}
7 changes: 6 additions & 1 deletion src/Wpf/Prism.Wpf/Modularity/ModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public ModuleManager(IModuleInitializer moduleInitializer, IModuleCatalog module
/// </summary>
protected IModuleCatalog ModuleCatalog { get; }

/// <summary>
/// Gets all the <see cref="IModuleInfo"/> classes that are in the <see cref="IModuleCatalog"/>.
/// </summary>
public IEnumerable<IModuleInfo> Modules => ModuleCatalog.Modules;

/// <summary>
/// Raised repeatedly to provide progress as modules are loaded in the background.
/// </summary>
Expand Down Expand Up @@ -68,7 +73,7 @@ public void Run()


/// <summary>
/// Loads and initializes the module on the <see cref="ModuleCatalog"/> with the name <paramref name="moduleName"/>.
/// Loads and initializes the module on the <see cref="IModuleCatalog"/> with the name <paramref name="moduleName"/>.
/// </summary>
/// <param name="moduleName">Name of the module requested for initialization.</param>
public void LoadModule(string moduleName)
Expand Down

0 comments on commit 413ca57

Please sign in to comment.