Makes things cross-platform
Certain types of things are basically impossible to do in cross-platform
mobile code today, yet there's no reason why. Writing a ViewModel that handles
loading a gallery of pictures from disk will be completely riddled with
#ifdefs and basically unreadable.
Splat aims to fix that, by providing a usable leaky abstraction above platform
code. It is leaky, because it always provides an extension method ToNative()
and FromNative(), which converts the abstraction to the platform-specific
version. Load the image in the cross-platform code, then call ToNative() in
your view to actually display it.
Splat currently supports:
Glenn WatsonMelbourne, Australia
Rodney Littles IITexas, USA
David VreonyUK
Chris PulmanUK
Always Be NuGetting. Package contains binaries for:
// If true, we are running unit tests
ModeDetector.InUnitTestRunner(); Splat provides a simple service location implementation that is optimized for Desktop and Mobile applications, while still remaining reasonably flexible.
There are 2 parts to the locator design:
To get a service:
// To get a single service registration
var toaster = AppLocator.Current.GetService();
// To get all service registrations
var allToasterImpls = AppLocator.Current.GetServices();Locator.Current is a static variable that can be set on startup, to adapt Splat to other DI/IoC frameworks. We're currently working from v7 onward to make it easier to use your DI/IoC framework of choice.
The default implementation of Service Location also allows new types to be registered at runtime.
// Create a new Toaster any time someone asks
Locator.CurrentMutable.Register(() => new Toaster(), typeof(IToaster));
// Register a singleton instance
Locator.CurrentMutable.RegisterConstant(new ExtraGoodToaster(), typeof(IToaster));
// Register a singleton which won't get created until the first user accesses it
Locator.CurrentMutable.RegisterLazySingleton(() => new LazyToaster(), typeof(IToaster));Starting with v19, Splat provides two high-performance resolver implementations optimized for AOT compilation: GlobalGenericFirstDependencyResolver and InstanceGenericFirstDependencyResolver. Both deliver significantly better performance than the legacy ModernDependencyResolver while supporting different isolation requirements. By default InstanceGenericFirstDependencyResolver is now the default container.
Note:
ModernDependencyResolver remains supported for backward compatibility, but new applications should strongly prefer one of the GenericFirst resolvers.
| Feature | GlobalGenericFirstDependencyResolver | InstanceGenericFirstDependencyResolver |
|---|---|---|
| Container Storage | Process-wide static containers | Per-resolver instance containers (ConditionalWeakTable) |
| Isolation | Shared across all resolver instances | Isolated per resolver instance |
| Performance | Fastest - direct static access | Very fast - one additional CWT lookup |
| Memory | Minimal - static fields only | Low - weak references, GC-friendly |
| Use Case | Single global service locator | Multiple independent resolvers, testing scenarios |
| Thread Safety | Lock-free reads, thread-safe writes | Lock-free reads, thread-safe writes |
| AOT Compatible | Yes | Yes |
The service locator is simple to use - register services at startup, then resolve them when needed:
// Register services at application startup
Locator.CurrentMutable.Register(() => new Toaster());
Locator.CurrentMutable.RegisterConstant(myConfig);
Locator.CurrentMutable.RegisterLazySingleton(() => new FileLogger());
// Resolve services anywhere in your application
var toaster = Locator.Current.GetService();
var config = Locator.Current.GetService();Key Concepts:
Register(() => new FastToaster(), "Fast")RegisterLazySingletonRegisterConstantSplat provides two resolver implementations with identical APIs but different tradeoffs around performance and state isolation.
Short version
Performance vs Isolation Tradeoff
The Global resolver achieves its speed by sharing static generic containers across the process. This is intentional and safe, but it means registrations are visible globally.
If global container state feels confusing or risky for your use case, choose the Instance resolver. The performance difference is measurable but rarely user-visible outside of very hot paths.
Based on internal benchmarks using realistic application workloads:
ModernDependencyResolver.For most applications, both are “fast enough”. The deciding factor is how much shared global state you are willing to expose to users.
The table below summarizes the practical performance and behavioral differences between Splat’s dependency resolvers, based on internal benchmarks using .NET 10 and realistic application workloads.
| Operation / Concern | GlobalGenericFirst | InstanceGenericFirst | ModernDependencyResolver |
|---|---|---|---|
| Service resolution (hit) | Fastest | Very fast (slightly slower than Global) | Slow |
| Service resolution (miss) | Fastest | Very fast (slightly slower than Global) | Very slow |
| Mixed workload (real application usage) | Fastest | ~25–30% slower than Global | ~3–4× slower |
| Bulk registration (startup) | Fastest | ~25–30% slower | Very slow (O(n²)) |
| Memory allocations | Lowest | Low (slightly higher than Global) | Very high |
| Scales to hundreds of services | Yes | Yes | Poor |
| Container state | Process-wide shared | Isolated per resolver instance | Isolated per resolver instance |
| Test isolation | Requires manual cleanup | Automatic | Automatic |
| AOT / NativeAOT support | Full | Full | Poor |
| Recommended for new code | Yes | Yes | No |
| Aspect | Global | Instance |
|---|---|---|
| Container state | Shared process-wide | Isolated per resolver |
| Surprise factor | Higher | Lower |
| Test isolation | Requires manual cleanup | Automatic |
| Performance | Fastest | Slightly slower |
| Debuggability | Harder (implicit coupling) | Easier (explicit ownership) |
For application authors
For library authors
For tests
…Both resolvers use a generic-first, two-tier architecture designed for maximum performance:
When you call generic methods like GetService(), the resolver uses static generic containers:
// Each type T gets its own static container - no dictionary lookups needed!
internal static class Container
{
private static readonly Entry> Entries = new();
// ... resolution logic
}Performance characteristics:
When you call Type-based methods like GetService(typeof(IToaster)), the resolver uses a concu
No open issues yet, or sync has not completed.