LoginForm: IStringLocalizer<LoginForm> injection is required in practice, breaks apps without AddLocalization() #35
Labels
No labels
breaking-change
bug
documentation
duplicate
enhancement
good first issue
help wanted
performance
question
wontfix
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Grandiras/ATProto.NET#35
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
v0.4.0 release notes describe the new
IStringLocalizer<LoginForm>support as optional ("when registered … default copy is resolved by parameter name"). In practice, rendering<LoginForm />in an app that has not calledservices.AddLocalization()throws:Hit while upgrading Updraft.Kanban from 0.3.0 → 0.4.0: the /login page 500s. Explicit
ButtonText/HandlePlaceholdervalues don't avoid it — the failure is at property-injection time, before parameters apply.Expected: the localizer should be optional as documented. Suggested fix: resolve via
IServiceProvider.GetService<IStringLocalizer<LoginForm>>()or an optional injection.Workaround for consumers:
builder.Services.AddLocalization();🤖 On it — follow along in the action run; the reply will link the full session transcript.
📜 Live transcript — updating every ~5 minutes while the task runs.
Fixed on branch
claude/issue-35.Cause
LoginFormdeclared the localizer as[Inject] private IStringLocalizer<LoginForm>? Localizer { get; set; }. Blazor's property injection resolves[Inject]members withGetRequiredService-style semantics — the?annotation has no effect on it — so the component demanded the service at activation time, before parameters were applied. That's why explicitButtonText/HandlePlaceholdervalues didn't help. The docs and release notes were correct about the intent; the wiring wasn't.Change
src/ATProtoNet.Blazor/Components/LoginForm.razornow injectsIServiceProviderand resolves the localizer lazily viaServices.GetService<IStringLocalizer<LoginForm>>(), cached after first lookup. Behaviour:No public API change; the
Localizermember was and remains private.Verification
Added
tests/ATProtoNet.Tests/Blazor/LoginFormTests.cs— three tests rendering the component throughHtmlRendereragainst a real service provider: no-localization, localizer-registered (including fallback for keys the localizer doesn't know), and explicit-parameter-wins..razorfile and it failed with exactlySystem.InvalidOperationException : Cannot provide a value for property 'Localizer' … There is no registered service of type 'Microsoft.Extensions.Localization.IStringLocalizer\1[ATProtoNet.Blazor.Components.LoginForm]'.`dotnet test tests/ATProtoNet.Tests/ -p:EnableSourceControlManagerQueries=false).Also updated
CHANGELOG.md(under[Unreleased]→Fixed) and added a line todocs/blazor.mdstating the localizer is optional and that apps withoutAddLocalization()need no setup.The
builder.Services.AddLocalization();workaround stays valid for anyone on 0.4.0 until this ships.→ Opened PR: #63
⏱ 3m 5s · 23 turns · 📜 Full session transcript
(reply recovered from the transcript — the posting step in runs before v12.3 was broken by a shell-quoting bug)