Skip to content

Conversation

ChrisPulman
Copy link
Member

What kind of change does this PR introduce?

Feature

What is the new behavior?

Introduces SplatRegistrationType to IViewFor attributes and source generator, enabling automatic registration of views for view models in Splat's service locator.

Locator.CurrentMutable.RegisterViewsForViewModelsSourceGenerated();

Updates documentation, tests, and sample usage to demonstrate new registration options and extension method for bulk registration.

What might this PR break?

None

Please check if the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

Other information:

Introduces SplatRegistrationType to IViewFor attributes and source generator, enabling automatic registration of views for view models in Splat's service locator. Updates documentation, tests, and sample usage to demonstrate new registration options and extension method for bulk registration.
@glennawatson glennawatson requested a review from Copilot October 4, 2025 02:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces Splat integration to the IViewFor source generator, enabling automatic registration of views with view models in Splat's service locator. It adds a SplatRegistrationType parameter to IViewFor attributes and generates an extension method for bulk registration of all views.

  • Adds SplatRegistrationType enum with options: None, LazySingleton, Constant, PerRequest
  • Extends IViewFor attributes to support RegistrationType parameter for Splat registration
  • Generates RegisterViewsForViewModelsSourceGenerated() extension method for bulk view registration

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
IViewForInfo.cs Adds SplatRegistrationType property to track registration type
IViewForGenerator.cs Updates generator to produce registration extension method
IViewForGenerator.Execute.cs Implements registration extension generation logic
AttributeDefinitions.cs Defines SplatRegistrationType enum and updates IViewFor attributes
Test files Updates examples to demonstrate Splat registration usage
README.md Documents new Splat registration functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

public static void Main() => Application.Run(new TestViewWinForms());
public static void Main()
{
AppLocator.CurrentMutable.RegisterViewsForViewModelsSourceGenerated();
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use Locator.CurrentMutable instead of AppLocator.CurrentMutable to match the Splat API and be consistent with other usages in the codebase.

Suggested change
AppLocator.CurrentMutable.RegisterViewsForViewModelsSourceGenerated();
Locator.CurrentMutable.RegisterViewsForViewModelsSourceGenerated();

Copilot uses AI. Check for mistakes.

public TestViewWpf() => ViewModel = TestViewModel.Instance;
public TestViewWpf()
{
Locator.CurrentMutable.RegisterLazySingleton<IViewFor<TestViewModel>>(() => new TestViewWpf());
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This manual registration should be removed since the PR introduces automatic registration via the generated extension method, making this redundant.

Suggested change
Locator.CurrentMutable.RegisterLazySingleton<IViewFor<TestViewModel>>(() => new TestViewWpf());

Copilot uses AI. Check for mistakes.

/// </summary>
/// <seealso cref="System.Attribute" />
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.IViewForGenerator", "1.1.0.0")]
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ReactiveObjectGenerator", "1.1.0.0")]
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GeneratedCode attribute should reference 'ReactiveUI.SourceGenerators.IViewForGenerator' instead of 'ReactiveObjectGenerator' for consistency with the actual generator.

Suggested change
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.ReactiveObjectGenerator", "1.1.0.0")]
[global::System.CodeDom.Compiler.GeneratedCode("ReactiveUI.SourceGenerators.IViewForGenerator", "1.1.0.0")]

Copilot uses AI. Check for mistakes.

/// </summary>
internal static class ReactiveUISourceGeneratorsExtensions
{
[global::System.CodeDom.Compiler.GeneratedCode("{{GeneratorName}}", "{{GeneratorVersion}}")]
Copy link
Preview

Copilot AI Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The template placeholders {{GeneratorName}} and {{GeneratorVersion}} are not being replaced with actual values, which will result in literal placeholder text in the generated code.

Copilot uses AI. Check for mistakes.

@ChrisPulman ChrisPulman merged commit 4a5d460 into main Oct 4, 2025
@ChrisPulman ChrisPulman deleted the IViewForRegistrations branch October 4, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants