Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align registration return type #3267

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading