Shiny.Extensions.DependencyInjection
5.1.6
Prefix Reserved
dotnet add package Shiny.Extensions.DependencyInjection --version 5.1.6
NuGet\Install-Package Shiny.Extensions.DependencyInjection -Version 5.1.6
<PackageReference Include="Shiny.Extensions.DependencyInjection" Version="5.1.6" />
<PackageVersion Include="Shiny.Extensions.DependencyInjection" Version="5.1.6" />
<PackageReference Include="Shiny.Extensions.DependencyInjection" />
paket add Shiny.Extensions.DependencyInjection --version 5.1.6
#r "nuget: Shiny.Extensions.DependencyInjection, 5.1.6"
#:package Shiny.Extensions.DependencyInjection@5.1.6
#addin nuget:?package=Shiny.Extensions.DependencyInjection&version=5.1.6
#tool nuget:?package=Shiny.Extensions.DependencyInjection&version=5.1.6
Shiny Extensions
Dependency Injection Extensions
- Source generate all attributed classes to a single add file - saves you the boilerplate
- Factory-form emission - generated registrations expand the constructor at compile time (no reflection, AOT-clean) so resolve chains like
OnResolvedcompose naturally ActivatorUtilities-style constructor selection ([ActivatorUtilitiesConstructor]and[FromKeyedServices]honored)- Optional/nullable constructor parameters are respected - resolved via
GetService(no throw when unregistered) with fallback to the declared default value - Multiple interfaces via explicit forwarders (no reflection)
- Supports open generics and keyed services
OnResolved<T>(hook)chain extension for one-shot post-construction hooks
The Results
THIS:
using Microsoft.Extensions.DependencyInjection;
using Shiny;
// given the following code from a user
namespace Sample
{
public interface IStandardInterface;
public interface IStandardInterface2;
[Service(ServiceLifetime.Singleton)]
public class ImplementationOnly;
[Service(ServiceLifetime.Transient, "ImplOnly")]
public class KeyedImplementationOnly;
[Service(ServiceLifetime.Singleton)]
public class StandardImplementation : IStandardInterface;
[Service(ServiceLifetime.Scoped, "Standard")]
public class KeyedStandardImplementation : IStandardInterface;
[Service(ServiceLifetime.Singleton)]
public class MultipleImplementation : IStandardInterface, IStandardInterface2;
[Service(ServiceLifetime.Scoped)]
public class ScopedMultipleImplementation : IStandardInterface, IStandardInterface2;
[Service(ServiceLifetime.Scoped, "KeyedGeneric")]
public class TestGeneric<T1, T2>
{
public T1 Value1 { get; set; }
public T2 Value2 { get; set; }
}
}
GENERATES THIS:
// <auto-generated />
using global::Microsoft.Extensions.DependencyInjection;
using global::Shiny;
namespace Sample
{
public static class __GeneratedRegistrations
{
public static global::Microsoft.Extensions.DependencyInjection.IServiceCollection AddGeneratedServices(
this global::Microsoft.Extensions.DependencyInjection.IServiceCollection services
)
{
services.AddSingleton<global::Sample.ImplementationOnly>();
services.AddKeyedTransient<global::Sample.KeyedImplementationOnly>("ImplOnly");
services.AddSingleton<global::Sample.IStandardInterface, global::Sample.StandardImplementation>();
services.AddKeyedScoped<global::Sample.IStandardInterface, global::Sample.KeyedStandardImplementation>("Standard");
services.AddSingletonAsImplementedInterfaces<global::Sample.MultipleImplementation>();
services.AddScopedAsImplementedInterfaces<global::Sample.ScopedMultipleImplementation>();
services.AddKeyedScoped(typeof(global::Sample.TestGeneric<,>), "KeyedGeneric");
return services;
}
}
}
Setup
- Install the NuGet package
Shiny.Extensions.DependencyInjection - Add the following using directive:
// during your app startup - use your service collection builder.Services.AddGeneratedServices(); - Add the
[Service(ServiceLifetime.Singleton, "optional key")]attribute to your classes and specify the lifetime and optional key
Serialization
- Centralized
ISerializerbacked by source-generatedJsonSerializerContexts, no reflection, AOT-clean Shiny.Jsonstatic accessor — self-bootstrapping, sibling toShiny.Storesfor mobile cold-start[ShinyJsonContext]on any user-declaredJsonSerializerContextpartial → source generator emits a[ModuleInitializer]that auto-registers it. Noservices.AddJsonContext(...)boilerplate needed[ShinyJsonInclude]on a type (or[assembly: ShinyJsonInclude(typeof(T))]) → AOT-safe collection wrappers forList<T>,T[],IEnumerable<T>,IReadOnlyList<T>,IList<T>,ICollection<T>,IAsyncEnumerable<T>— solves the "inline[JsonConverter]works butList<T>fails" trap- Multiple contributing libraries chain cleanly via
TypeInfoResolverChain. Element types from one context compose with collection wrappers from another services.AddJsonSerialization()/AddJsonContext(...)/ConfigureJsonSerializer(...)for DI-side wiring;Shiny.Json.CreateTestScope()for test isolation
Setup
- Install the NuGet package
Shiny.Extensions.Serialization - Write a normal STJ source-generator context and decorate it with
[Shiny.ShinyJsonContext]:using System.Text.Json.Serialization; using Shiny; [ShinyJsonContext] [JsonSerializable(typeof(MyDto))] [JsonSerializable(typeof(MyOtherDto))] internal partial class MyAppJsonContext : JsonSerializerContext; - Done. The generator emits a
[ModuleInitializer]callingShiny.Json.AddContext(MyAppJsonContext.Default)beforeMain, so both DI consumers and the staticShiny.Json.Defaultaccessor see your types — noservices.AddJsonContext(...)call needed. - (Optional) For collection support, mark element types with
[ShinyJsonInclude]:[ShinyJsonInclude] public partial class MyDto { /* ... */ }List<MyDto>,MyDto[],IEnumerable<MyDto>and friends now serialize AOT-safely.
// Static access — works before DI exists (useful for mobile cold-start through Shiny.Stores)
var json = Shiny.Json.Default.Serialize(new MyDto { Name = "Allan" });
// DI access — same shared instance
public class MyService(ISerializer serializer) { /* ... */ }
Stores
- Cross-platform key/value store with support for
- Android/iOS/Windows - Preferences & Secure Storage
- Web - Local Storage
- In Memory
- Source-generated
[Bind]attribute on partial properties - emits getter/setter bodies that round-trip through the store (no INPC required, no runtime reflection, fully AOT) - Static
Shiny.Stores.Default/Secure/Keyed(...)accessor for direct ad-hoc reads/writes - Implement
IKeyValueStoreto plug in your own store
Setup
Install the NuGet package
Shiny.Extensions.StoresRegister at startup — the static
Shiny.Storesaccessor self-bootstraps on first use:builder.Services.AddShinyStores(); var host = builder.Build();On Blazor WebAssembly (where
LocalStorageKeyValueStoreneedsIJSRuntime), also callhost.Services.UseShinyStores()afterBuild()to snapshot the DI-resolved store into the static accessor.AddShinyStores()registersIKeyValueStorekeyed underStoreKeys.DefaultandStoreKeys.Secure, plus the default store unkeyed. The unkeyed registration exists for third-party container adapters that predate .NET 8 keyed services — Prism's DryIoc container, for example, still sits on DryIoc 5.x, silently ignores[FromKeyedServices], and resolves the plainIKeyValueStoreinstead. On those containers, use the staticShiny.Stores.Secure/Shiny.Stores.Keyed(...)accessor when you need a non-default store, since the key will be dropped.Define your settings as a
partialclass with[Bind]partial properties:using Shiny; [Singleton] public partial class AppSettings { [Bind] // default store public partial string Theme { get; set; } [Bind("secure")] // secure store public partial string Token { get; set; } }Inject
AppSettingsanywhere. Set properties — they persist. Read properties — they come from the store.
Or skip the class and use the static accessor:
Shiny.Stores.Default.Set("theme", "dark");
var theme = Shiny.Stores.Default.Get<string>("theme");
Available Stores Per Platform
| Platform | Key | Description |
|---|---|---|
| Android | StoreKeys.Default |
Preferences |
| Android | StoreKeys.Secure |
Secure Storage |
| iOS | StoreKeys.Default |
NSUserDefaults |
| iOS | StoreKeys.Secure |
Keychain |
| Windows (packaged) | StoreKeys.Default |
ApplicationData.LocalSettings |
| Windows (packaged) | StoreKeys.Secure |
Secure Storage (DPAPI) |
| Windows (unpackaged) | StoreKeys.Default |
JSON file (LocalApplicationData) |
| Windows (unpackaged) | StoreKeys.Secure |
JSON file + DPAPI encryption |
macOS (net10.0-macos) |
StoreKeys.Default |
NSUserDefaults |
macOS (net10.0-macos) |
StoreKeys.Secure |
Keychain |
| Linux / other desktop | StoreKeys.Default |
JSON file (LocalApplicationData) |
| Linux / other desktop | StoreKeys.Secure |
JSON file (not encrypted) |
| WebAssembly | StoreKeys.Default |
localStorage |
| WebAssembly | "session" |
sessionStorage |
| All | any | In-memory dictionary (via MemoryKeyValueStore, great for testing) |
For WebAssembly, install the Shiny.Extensions.Stores.Web package and add services.AddShinyWebAssemblyStores() to your service collection.
A dedicated net10.0-macos target gives plain macOS apps NSUserDefaults + Keychain (real secure storage). Other desktop targets that resolve the base net10.0 asset (Linux, and unpackaged Windows) persist both Default and Secure to a JSON file under {LocalApplicationData}/{EntryAssemblyName} so settings survive restarts. Override the location by setting Shiny.Stores.FileStoreDirectory before first access. On these file fallbacks Secure is not encrypted (unpackaged Windows keeps DPAPI over the file) — treat it as obfuscation, not protection, for sensitive data.
On Apple platforms the default store is scoped to the app's own preferences domain. NSUserDefaults.StandardUserDefaults is a search list — it also resolves through the global domain and through defaults any linked framework registered — so Contains/Get deliberately ask the app's persistent domain instead. Without that, an ordinary key name (AutoRecord, UseMetric, Enabled) can read back as present having never been written, and Get(key, defaultValue) would hand back that foreign value instead of your default.
Web Hosting Extensions
- Merges service container build and post build scenarios into a single class using
IWebModule
Setup
- Install the NuGet package
Shiny.Extensions.WebHosting - Add a web module by implementing
IWebModule:using Shiny; public class MyWebModule : IWebModule { public void Add(WebApplicationBuilder builder) { // Register your services here } public void Use(WebApplication app) { // Configure your middleware/endpoints here } } - In your application hosting startup, add the following:
using Shiny; var builder = WebApplication.CreateBuilder(args); builder.AddInfrastructureModules(new MyWebModule()); var app = builder.Build(); app.UseInfrastructureModules();
MAUI Hosting Extensions
- Module-based MAUI app configuration with
IMauiModule - Static
Host.Servicesfor accessing the service provider anywhere IAppSupport— device info (manufacturer, model, platform, idiom, OS version), browser/map launch, programmatic orientation lock, and live change events for orientation, culture, and time zone (native listeners on iOS/Android/Windows, polling fallback elsewhere)IAppStore— cross-platform store version lookups + deep links for Apple App Store (iTunes Search API), Google Play (HTML scrape), and Microsoft Store (DisplayCatalog API)- Opt-in registration: each capability is its own extension method so apps only pay for what they use
Setup
- Install the NuGet package
Shiny.Extensions.MauiHosting - Create a MAUI module by implementing
IMauiModule:using Shiny; public class MyMauiModule : IMauiModule { public void Add(MauiAppBuilder builder) { // Register your services here } public void Use(IPlatformApplication app) { // Post-build initialization here (do NOT block) } } - In your
MauiProgram.cs:using Shiny; var builder = MauiApp.CreateBuilder(); builder .UseMauiApp<App>() .AddInfrastructureModules(new MyMauiModule()) // your IMauiModule list .AddAppSupport() // IAppSupport .AddAppStore(opts => // optional: IAppStore + config { opts.AppleAppId = "1234567890"; opts.WindowsProductId = "9NBLGGH4NNS1"; }); return builder.Build(); - Access services anywhere via
Host.Services
IAppSupport
public class MyVm(IAppSupport app)
{
void Hook()
{
// Snapshot
var version = app.AppVersion;
var platform = app.Platform; // "Android", "iOS", "WinUI", "macOS"
var idiom = app.DeviceIdiom; // Phone, Tablet, Desktop, …
var orientation = app.CurrentOrientation;
var culture = app.CurrentCulture;
// Live updates
app.OrientationChanged += (s, e) => { /* new DisplayOrientation */ };
app.CultureChanged += (s, e) => { /* new CultureInfo */ };
app.TimeZoneChanged += (s, e) => { /* new TimeZoneInfo */ };
// Programmatic orientation lock
_ = app.SetOrientation(DisplayOrientation.Landscape);
_ = app.ResetOrientation();
}
}
IAppStore
public class UpdateChecker(IAppStore store)
{
public async Task Check()
{
var result = await store.GetCurrent();
if (result?.NeedsUpdate == true)
await store.OpenStore();
}
public Task Review() => store.OpenReviewPage();
}
Blazor WebAssembly Hosting Extensions
IAppSupportfor Blazor WebAssembly — app version, browser user-agent (raw string + best-effort parsed browserVersion), screen and viewport dimensions, plus live culture / time-zone change events- Reads browser state synchronously through
IJSInProcessRuntime(same approach asShiny.Extensions.Stores.Web)
Setup
- Install the NuGet package
Shiny.Extensions.BlazorHosting - Reference the bundled script in
wwwroot/index.htmlbeforeblazor.webassembly.js:<script src="_content/Shiny.Extensions.BlazorHosting/shiny-appsupport.js"></script> - Register at startup, passing the head app's version (no reflection — use the source-generated
ThisAssembly):using Shiny; builder.Services.AddAppSupport(ThisAssembly.AssemblyVersion); - Inject
IAppSupportanywhere:public class MyComponent(IAppSupport app) { void Hook() { // Snapshot var version = app.AppVersion; var ua = app.UserAgent; var browser = app.UserAgentVersion; var (w, h) = (app.BrowserWidth, app.BrowserHeight); // viewport — read live var (sw, sh) = (app.ScreenWidth, app.ScreenHeight); // physical screen // Live updates app.CultureChanged += (s, e) => { /* new CultureInfo */ }; app.TimeZoneChanged += (s, e) => { /* new TimeZoneInfo */ }; } }
Additional Libraries Used
- Shiny Reflector - Reflection without the actual reflection
NuGet Packages
| Package | Description |
|---|---|
Shiny.Extensions.DependencyInjection |
Attribute-driven DI registration with source generators |
Shiny.Extensions.Serialization |
Centralized AOT-safe JSON serializer + [ShinyJsonContext]/[ShinyJsonInclude] source generator |
Shiny.Extensions.Stores |
Cross-platform key/value store abstraction |
Shiny.Extensions.Stores.Web |
Blazor WebAssembly localStorage/sessionStorage |
Shiny.Extensions.WebHosting |
ASP.NET modular web hosting with IWebModule |
Shiny.Extensions.MauiHosting |
MAUI modular hosting with IMauiModule and platform lifecycle hooks |
Shiny.Extensions.BlazorHosting |
Blazor WebAssembly IAppSupport — browser/device info and culture/time-zone change events |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Shiny.Extensions.Stores (>= 5.1.6)
NuGet packages (37)
Showing the top 5 NuGet packages that depend on Shiny.Extensions.DependencyInjection:
| Package | Downloads |
|---|---|
|
Shiny.Core
The Shiny Core Foundation where all Shiny modules are built on |
|
|
Shiny.Notifications
Shiny addon for all your notification needs |
|
|
Shiny.Push
Shiny addon for all your push notification needs |
|
|
Shiny.BluetoothLE.Common
Shiny BluetoothLE - Common components for Hosting and Client |
|
|
Shiny.BluetoothLE
Shiny Reactive BluetoothLE Plugin for client/central operations |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Shiny.Extensions.DependencyInjection:
| Repository | Stars |
|---|---|
|
shinyorg/templates
dotnet CLI & Visual Studio Templates
|
| Version | Downloads | Last Updated |
|---|---|---|
| 5.1.6 | 0 | 9/2/2026 |
| 5.1.5 | 8,105 | 8/7/2026 |
| 5.1.4 | 9,300 | 7/15/2026 |
| 5.1.3 | 111 | 7/15/2026 |
| 5.1.2 | 425 | 7/3/2026 |
| 5.1.1 | 11,878 | 6/20/2026 |
| 5.1.0 | 1,162 | 6/14/2026 |
| 5.1.0-beta-0054 | 116 | 6/14/2026 |
| 5.1.0-beta-0052 | 121 | 6/12/2026 |
| 5.1.0-beta-0051 | 122 | 6/12/2026 |
| 5.0.0 | 334 | 6/8/2026 |
| 5.0.0-beta-0052 | 410 | 6/7/2026 |
| 5.0.0-beta-0051 | 4,314 | 6/7/2026 |
| 4.1.1 | 1,839 | 6/1/2026 |
| 4.1.0 | 3,051 | 5/29/2026 |
| 4.0.0 | 145 | 5/28/2026 |
| 4.0.0-beta-0063 | 130 | 5/27/2026 |
| 4.0.0-beta-0062 | 120 | 5/27/2026 |
| 4.0.0-beta-0061 | 121 | 5/27/2026 |
| 4.0.0-beta-0060 | 119 | 5/27/2026 |