Skip to content

feat!: Drop CommonServiceLocator from Uno.Core.Extensions.Compatibility - #98

Merged
MartinZikmund merged 5 commits into
masterfrom
dev/mz/drop-commonservicelocator-compat
Oct 8, 2026
Merged

MartinZikmund merged 5 commits into
masterfrom
dev/mz/drop-commonservicelocator-compat

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

What

Follow-up to #94, which removed CommonServiceLocator from LogExtensionPoint but deliberately left Uno.Core.Extensions.Compatibility alone. That exemption is why the Uno.Core package still lists CommonServiceLocator among its dependencies.

This PR removes the last three usages, so the dependency is gone from the package graph entirely.

Why

Same reasoning as #94 — CommonServiceLocator is Microsoft.Practices.ServiceLocation, copyright Microsoft 2008, under the MS-PL, which the FSF classifies as incompatible with the GPL. #94 stopped it shipping inside every Uno app; this one stops Uno.Core advertising it at all.

How

ExtensionsProvider — backs ConversionExtensions.Implementation and ReflectionExtensions.Implementation, letting a consumer substitute an implementation. Moved to System.IServiceProvider with a settable ExtensionsProvider.ServiceProvider, exactly as LogExtensionPoint.ServiceProvider works after #94.

Uno.IServiceLocatorProvider and Uno.Extensions.ServiceLocatorProviderExtensions — deleted, along with their TypeForwardedTo entries. Both existed purely to hand out an IServiceLocator; neither can survive the dependency going away in any useful form. GitHub code search across the whole unoplatform org finds zero consumers of either, ExtensionsProvider included — every hit is Uno.Core's own source.

Packaging — drops the PackageReference from Uno.Core and Uno.Core.Extensions.Compatibility, and stops Uno.Core.Build packing CommonServiceLocator.dll into its build folder.

One behaviour fix that comes along

Get<TService>(Func<TService>) had an operator-precedence bug:

var service =
    ServiceLocator.IsLocationProviderSet ? ServiceLocator.Current.GetInstance<TService>() : null
    ?? defaultFactory();

?: binds looser than ??, so ?? defaultFactory() only ever applied to the null branch — a locator that was set but could not resolve returned null. That was survivable because IServiceLocator.GetInstance threw for an unregistered service. IServiceProvider.GetService returns null instead, so keeping the shape would hand back null from every unregistered lookup. The fallback now applies to both paths.

Breaking change

Consumers who substituted an implementation via ServiceLocator.SetLocatorProvider(...) assign ExtensionsProvider.ServiceProvider instead:

// before
ServiceLocator.SetLocatorProvider(() => myLocator);

// after
ExtensionsProvider.ServiceProvider = myServiceProvider; // e.g. an MS.DI IServiceProvider

Consumers of IServiceLocatorProvider / .ServiceLocation() have no replacement — see above for why that surface is believed to be unused.

Validation

Runtime — dotnet test Uno.Core.Tests: 268 passed, 0 failed, 2 skipped.

The five conversion fixtures registered their services through a FunqAdapter : IServiceLocator; they now use a small TestServiceProvider : IServiceProvider that caches each registration after first resolve, the way Funq's default hierarchy scope did (CustomConversionStrategyFixture needs the resolved instance to be the one it mutates). Funq was pulled in for that adapter alone and is dropped.

Negative control — removing the ExtensionsProvider.ServiceProvider = _container line from CustomConversionStrategyFixture turns it red, so the fixtures genuinely exercise the new resolution path rather than falling through to the defaults.

Package — packed Uno.Core and Uno.Core.Extensions.Compatibility and read the generated .nuspec. No CommonServiceLocator dependency in either:

<dependency id="Uno.Core.Extensions.Compatibility" ... />
<dependency id="Microsoft.Extensions.Logging" version="1.1.1" ... />
<dependency id="System.Collections.Immutable" version="1.3.1" ... />
<dependency id="System.Memory" version="4.5.2" ... />
<dependency id="System.Reflection.Emit.Lightweight" version="4.3.0" ... />
<dependency id="System.ValueTuple" version="4.4.0" ... />

Unrelated commit riding along

test: Take fr-FR's group separator from the culture — ValidationHelperFixture asserts IsCurrency against a hardcoded plain space, but fr-FR's currency group separator is U+202F in current locale data. It fails on master on any machine with a new enough ICU, independently of this change. Happy to split it out if you'd rather.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GrFrHWth7YEzqGawxNiroK

MartinZikmund and others added 3 commits September 10, 2026 14:53
BREAKING CHANGE: `Uno.IServiceLocatorProvider` and
`Uno.Extensions.ServiceLocatorProviderExtensions` are removed, and consumers who
substituted an `IConversionExtensions` or `IReflectionExtensions` through
`ServiceLocator.SetLocatorProvider` must now assign
`ExtensionsProvider.ServiceProvider` instead.

PR #94 replaced CommonServiceLocator in `LogExtensionPoint` but deliberately left
`Uno.Core.Extensions.Compatibility` alone, so the `Uno.Core` package still lists
CommonServiceLocator among its dependencies. That package is
Microsoft.Practices.ServiceLocation under the MS-PL, which the FSF classifies as
GPL-incompatible, over a service locator API that predates
Microsoft.Extensions.DependencyInjection.

The two `IServiceLocator`-typed public types existed only to hand out a locator
and have no consumer anywhere in the unoplatform org, so they are removed rather
than retyped. `ExtensionsProvider` moves to `System.IServiceProvider`, matching
what `LogExtensionPoint` already does.

 - Add `ExtensionsProvider.ServiceProvider`, an optional `IServiceProvider` used
   to resolve `IConversionExtensions` / `IReflectionExtensions`
 - Delete `IServiceLocatorProvider` and `ServiceLocatorProviderExtensions`, and
   their `TypeForwardedTo` entries
 - Drop the `CommonServiceLocator` PackageReference from `Uno.Core` and
   `Uno.Core.Extensions.Compatibility`, and stop packing
   `CommonServiceLocator.dll` into `Uno.Core.Build`

`Get<TService>(Func<TService>)` also loses an operator-precedence bug: `?:` binds
looser than `??`, so the `?? defaultFactory()` only ever applied to the branch
that was already `null`. A locator that was set but could not resolve returned
`null`. `IServiceProvider.GetService` returns `null` for an unregistered service
where `IServiceLocator.GetInstance` threw, so the fallback now applies to both
paths - otherwise every unregistered lookup would hand back `null`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GrFrHWth7YEzqGawxNiroK
The fixtures registered their `IConversionExtensions` / `IReflectionExtensions`
through `ServiceLocator.SetLocatorProvider`, wrapping a Funq container in a
`FunqAdapter : IServiceLocator`. Funq was pulled in for that adapter alone.

`TestServiceProvider` replaces both. It caches each registration after the first
resolve, the way Funq's default hierarchy scope did, so a test can still mutate
the very instance the code under test resolves - `CustomConversionStrategyFixture`
depends on that when it registers a strategy on the resolved instance.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GrFrHWth7YEzqGawxNiroK
`IsCurrency` was asserted against a hardcoded plain space. fr-FR's currency group
separator is U+202F (narrow no-break space) in current locale data, so the
assertion fails on any machine with an ICU new enough to carry the change. Read
the separator from the culture instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GrFrHWth7YEzqGawxNiroK
Copilot AI lite review requested due to automatic review settings September 10, 2026 12:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

ExtensionsProvider.Resolve<TService>() currently masks misconfigured service registrations by silently falling back when the provider returns the wrong type, which can hide wiring errors.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR removes the remaining CommonServiceLocator dependency from Uno.Core.Extensions.Compatibility by switching the ExtensionsProvider extension-resolution hook from IServiceLocator to System.IServiceProvider, and updates tests/packaging so the dependency disappears from the shipped package graph.

Changes:

  • Drop CommonServiceLocator package references (and stop packing CommonServiceLocator.dll) across Uno.Core, Uno.Core.Extensions.Compatibility, and Uno.Core.Build.
  • Replace ExtensionsProvider’s service-locator-based resolution with an optional IServiceProvider (ExtensionsProvider.ServiceProvider) plus fallback behavior.
  • Update conversion tests to use a minimal TestServiceProvider, remove the Funq adapter, and fix a fr-FR currency-group-separator assertion to use culture data.
File summaries
File Description
src/Uno.Core/Uno.Core.csproj Removes CommonServiceLocator dependency from the core package.
src/Uno.Core/ForwardedTypes.cs Removes type forwarding for deleted service-locator compatibility APIs.
src/Uno.Core.Tests/Validation/ValidationHelperFixture.cs Makes fr-FR currency validation resilient to updated ICU locale data.
src/Uno.Core.Tests/Uno.Core.Tests.csproj Removes Funq test dependency.
src/Uno.Core.Tests/Conversions/TypeConverterConversionStrategyFixture.cs Switches test initialization from ServiceLocator to ExtensionsProvider.ServiceProvider.
src/Uno.Core.Tests/Conversions/TestServiceProvider.cs Introduces a cached, minimal IServiceProvider implementation for tests.
src/Uno.Core.Tests/Conversions/FunqAdapter.cs Removes the Funq→IServiceLocator adapter used only for tests.
src/Uno.Core.Tests/Conversions/EnumConversionStrategyFixture.cs Switches tests to ExtensionsProvider.ServiceProvider.
src/Uno.Core.Tests/Conversions/DefaultConversionsExtensionsFixture.cs Switches tests to ExtensionsProvider.ServiceProvider and TestServiceProvider.
src/Uno.Core.Tests/Conversions/CustomConversionStrategyFixture.cs Switches tests to ExtensionsProvider.ServiceProvider and TestServiceProvider.
src/Uno.Core.Tests/Conversions/ConversionExtensionsFixture.cs Switches tests to ExtensionsProvider.ServiceProvider.
src/Uno.Core.Extensions.Compatibility/Uno.Core.Extensions.Compatibility.csproj Removes CommonServiceLocator dependency from compatibility package.
src/Uno.Core.Extensions.Compatibility/IServiceLocatorProvider.cs Deletes service-locator compatibility interface.
src/Uno.Core.Extensions.Compatibility/Extensions/ExtensionsProvider.cs Replaces service-locator resolution with IServiceProvider-based resolution and fallback.
src/Uno.Core.Build/Uno.Core.Build.csproj Stops packing CommonServiceLocator.dll into the build assets.
Review details
  • Files reviewed: 15/15 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

MartinZikmund and others added 2 commits September 10, 2026 15:18
`Resolve<TService>` used `as TService`, so an `IServiceProvider` that answered
`GetService(typeof(IConversionExtensions))` with something that is not an
`IConversionExtensions` was indistinguishable from one that provided nothing, and
the default implementation was used. That is the more insidious of the two
failures: the custom implementation is simply ignored, silently, forever.

`GetService` returning a non-assignable instance violates the `IServiceProvider`
contract, so treat it as the wiring error it is. Missing still falls back.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GrFrHWth7YEzqGawxNiroK
Pins all three outcomes: no provider and a provider without the service both fall
back to the default, a provided service is used as-is, and a wrong-typed one
throws. The last one fails against the previous `as TService` implementation.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GrFrHWth7YEzqGawxNiroK

@morning4coffe-dev morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The dependency removal is coherent across Compatibility, the umbrella package, build payload and type forwarders. ExtensionsProvider now uses the existing IServiceProvider model, preserves supplied services, falls back for an absent provider/service, and explicitly rejects an incompatible supplied object. The factory-overload precedence correction is necessary with GetService's null-on-miss contract. The fixtures retain per-registration instance identity and cover the new fallback/error paths. The removed public locator surface is correctly called out as breaking; this has no WinUI control-engine behavior implication.

@mergify

mergify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

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.

3 participants