Use Avalonia-generated InitializeComponent#1075
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8af6a15e6e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff9ef93bfd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 184080bc77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PR Summary: Use Avalonia-generated
InitializeComponentBranch
feat/avalonia-generated-initializecomponentGoal
Remove explicit
AvaloniaXamlLoader.Load(this)usage from Dock views and user controls, move sample projects to Avalonia's generatedInitializeComponentpath, and keep the solution building cleanly under the generator-based setup.Why this change
The local Avalonia source confirms that
AvaloniaNameGeneratorBehavior=InitializeComponentis the mode that generates both named-part properties and theInitializeComponentimplementation for supported view types. That makes handwrittenAvaloniaXamlLoader.Load(this)wrappers in view code-behind redundant.The same review also showed an important distinction for
Application:StyledElement-based views can rely on the name generator.Applicationloading follows Avalonia's compiler path instead of the name generator path.Because of that, this PR removes manual loader calls from
App.axaml.csfiles only where Avalonia can inject the load through the trivial default constructor path, and it refactors the DI sample so it also fits that model.Scope
InitializeComponentApp.axaml.csfiles cleaned upApp.axaml.csfiles cleaned upWhat changed
1. Sample projects now use generated
InitializeComponent24 sample projects that previously used
AvaloniaNameGeneratorBehavior=OnlyPropertiesnow useAvaloniaNameGeneratorBehavior=InitializeComponent.This aligns the project setting with the desired runtime/code-behind pattern:
InitializeComponent();private void InitializeComponent()wrapper is neededAvaloniaXamlLoader.Load(this)remains in view/user control/window code-behindRepresentative files:
samples/DockReactiveUISample/DockReactiveUISample.csprojsamples/DockReactiveUIDiSample/DockReactiveUIDiSample.csprojsamples/DockXamlSample/DockXamlSample.csprojsamples/WebViewSample/WebViewSample.csproj2. Sample views and windows were simplified
195 sample view code-behind files were updated to use the generated implementation directly. In most cases this was a pure deletion of the handwritten loader method. Constructors now stay limited to:
Representative files:
samples/DockReactiveUISample/Views/MainWindow.axaml.cssamples/DockReactiveUIRoutingSample/Views/DockView.axaml.cssamples/DockFigmaSample/Views/WorkspaceView.axaml.cssamples/Notepad/Views/MainView.axaml.csOne small structural cleanup was kept where post-load work already existed:
samples/DockXamlSample/MainView.axaml.cs3. Diagnostics controls now follow the same generated path
19 controls in
src/Dock.Avalonia.Diagnostics/Controlshad localAvaloniaXamlLoader.Load(this)wrappers removed. These controls now match the rest of the codebase and rely on Avalonia's generated initializer.Representative files:
src/Dock.Avalonia.Diagnostics/Controls/DockDebugView.axaml.cssrc/Dock.Avalonia.Diagnostics/Controls/RootDockDebug.axaml.cssrc/Dock.Avalonia.Diagnostics/Controls/ToolDockDebugView.axaml.cs4. Sample and test
Appclasses no longer callAvaloniaXamlLoader.Load(this)The remaining
App.axaml.csoccurrences were removed from:These classes now rely on Avalonia's compiler-generated application initialization path instead of explicit manual loading.
Representative files:
samples/DockReactiveUISample/App.axaml.cssamples/BrowserTabTheme/App.axaml.cssamples/WebViewSample/App.axaml.cstests/Dock.Avalonia.UnitTests/App.axaml.cs5.
DockReactiveUIDiSamplestartup was refactoredThe DI sample previously depended on a custom
Appconstruction pattern. That made it the main exception once explicitApploader calls were removed.The sample was refactored so
Appcan still be created through a trivial constructor and receive dependencies after construction:Appnow exposes init-only properties:ServiceProviderViewLocatorInitialize()only inserts theViewLocatordata template when availableProgram.csno longer registersAppas a container singletonAppBuilder.Configure(...)now uses a factory that createsAppand sets the init propertiesFiles:
samples/DockReactiveUIDiSample/App.axaml.cssamples/DockReactiveUIDiSample/Program.cs6. Documentation was updated
The ReactiveUI DI article contained the now-stale constructor-based
Apppattern and a manual loader call. The article was updated to match the new implementation.File:
docfx/articles/dock-reactiveui-di.mdRemaining explicit loader calls
Only intentional service-provider-based theme loads remain:
src/Dock.Avalonia.Themes.Fluent/DockFluentTheme.axaml.cssrc/Dock.Avalonia.Themes.Simple/DockSimpleTheme.axaml.cssrc/Dock.Avalonia.Themes.Browser/Styles/BrowserTabTheme.axaml.csThese are not
Load(this)calls and were left unchanged.Commit breakdown
997d893b4refactor(samples): use generated InitializeComponent in sample viewsf5a848d21refactor(diagnostics): use generated InitializeComponentd34246ee0refactor(apps): remove manual App XAML loader calls740817590refactor(di): simplify DockReactiveUIDiSample app startup8af6a15e6docs: update ReactiveUI DI app initializationValidation
Search validation
The exact search below returns no source matches outside
obj:Build validation
Result: build succeeded.
Known remaining warnings
These warnings were present outside the scope of this migration and were not changed by this PR:
CS1591insrc/Dock.Controls.Recycling/RecylingDataTemplate.csIL2026/IL3050ReactiveUI trim/AOT warnings in several sample projectsCS0618insamples/DockCodeOnlySample/Program.csCS0067intests/Dock.Avalonia.LeakTestsReview notes
InitializeComponent();only and should not add localAvaloniaXamlLoader.Load(this)wrappers back.Apprefactors should preserve Avalonia's application-loading expectations. If constructor injection is reintroduced, the startup path should be reviewed carefully soApp.axamlstill loads through Avalonia's compiler path.