Skip to content

Commit

Permalink
chore: align registration return type
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Oct 22, 2024
1 parent ec09b17 commit 0c9338b
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions src/Wpf/Prism.Wpf/Ioc/IContainerRegistryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ public static class IContainerRegistryExtensions
/// <typeparam name="TView">The Type of object to register as the dialog</typeparam>
/// <param name="containerRegistry"></param>
/// <param name="name">The unique name to register with the dialog.</param>
public static void RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IContainerRegistry containerRegistry, string name = null)
{
public static IContainerRegistry RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView>(this IContainerRegistry containerRegistry, string name = null) =>
containerRegistry.RegisterForNavigation<TView>(name);
}

/// <summary>
/// Registers an object to be used as a dialog in the IDialogService.
Expand All @@ -26,54 +24,46 @@ public static class IContainerRegistryExtensions
/// <typeparam name="TViewModel">The ViewModel to use as the DataContext for the dialog</typeparam>
/// <param name="containerRegistry"></param>
/// <param name="name">The unique name to register with the dialog.</param>
public static void RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, string name = null) where TViewModel : Dialogs.IDialogAware
{
public static IContainerRegistry RegisterDialog<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, string name = null) where TViewModel : Dialogs.IDialogAware =>
containerRegistry.RegisterForNavigation<TView, TViewModel>(name);
}

/// <summary>
/// Registers an object that implements IDialogWindow to be used to host all dialogs in the IDialogService.
/// </summary>
/// <typeparam name="TWindow">The Type of the Window class that will be used to host dialogs in the IDialogService</typeparam>
/// <param name="containerRegistry"></param>
public static void RegisterDialogWindow<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TWindow>(this IContainerRegistry containerRegistry) where TWindow : Dialogs.IDialogWindow
{
public static IContainerRegistry RegisterDialogWindow<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TWindow>(this IContainerRegistry containerRegistry) where TWindow : Dialogs.IDialogWindow =>
containerRegistry.Register(typeof(Dialogs.IDialogWindow), typeof(TWindow));
}

/// <summary>
/// Registers an object that implements IDialogWindow to be used to host all dialogs in the IDialogService.
/// </summary>
/// <typeparam name="TWindow">The Type of the Window class that will be used to host dialogs in the IDialogService</typeparam>
/// <param name="containerRegistry"></param>
/// <param name="name">The name of the dialog window</param>
public static void RegisterDialogWindow<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TWindow>(this IContainerRegistry containerRegistry, string name) where TWindow : Dialogs.IDialogWindow
{
public static IContainerRegistry RegisterDialogWindow<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TWindow>(this IContainerRegistry containerRegistry, string name) where TWindow : Dialogs.IDialogWindow =>
containerRegistry.Register(typeof(Dialogs.IDialogWindow), typeof(TWindow), name);
}

/// <summary>
/// Registers an object for navigation
/// </summary>
/// <param name="containerRegistry"></param>
/// <param name="type">The type of object to register</param>
/// <param name="name">The unique name to register with the object.</param>
public static void RegisterForNavigation(this IContainerRegistry containerRegistry, Type type, string name)
{
public static IContainerRegistry RegisterForNavigation(this IContainerRegistry containerRegistry, Type type, string name) =>
containerRegistry.Register(typeof(object), type, name);
}

/// <summary>
/// Registers an object for navigation.
/// </summary>
/// <typeparam name="T">The Type of the object to register as the view</typeparam>
/// <param name="containerRegistry"></param>
/// <param name="name">The unique name to register with the object.</param>
public static void RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IContainerRegistry containerRegistry, string name = null)
public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>(this IContainerRegistry containerRegistry, string name = null)
{
Type type = typeof(T);
string viewName = string.IsNullOrWhiteSpace(name) ? type.Name : name;
containerRegistry.RegisterForNavigation(type, viewName);
return containerRegistry.RegisterForNavigation(type, viewName);
}

/// <summary>
Expand All @@ -83,18 +73,16 @@ public static void RegisterForNavigation(this IContainerRegistry containerRegist
/// <typeparam name="TViewModel">The ViewModel to use as the DataContext for the view</typeparam>
/// <param name="containerRegistry"></param>
/// <param name="name">The unique name to register with the view</param>
public static void RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, string name = null)
{
public static IContainerRegistry RegisterForNavigation<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TView, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, string name = null) =>
containerRegistry.RegisterForNavigationWithViewModel<TViewModel>(typeof(TView), name);
}

private static void RegisterForNavigationWithViewModel<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, Type viewType, string name)
private static IContainerRegistry RegisterForNavigationWithViewModel<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] TViewModel>(this IContainerRegistry containerRegistry, Type viewType, string name)
{
if (string.IsNullOrWhiteSpace(name))
name = viewType.Name;

ViewModelLocationProvider.Register(viewType.ToString(), typeof(TViewModel));
containerRegistry.RegisterForNavigation(viewType, name);
return containerRegistry.RegisterForNavigation(viewType, name);
}
}
}

0 comments on commit 0c9338b

Please sign in to comment.