Shiny.Extensions.DependencyInjection 1.0.3

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Shiny.Extensions.DependencyInjection --version 1.0.3
                    
NuGet\Install-Package Shiny.Extensions.DependencyInjection -Version 1.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Shiny.Extensions.DependencyInjection" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Shiny.Extensions.DependencyInjection" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Shiny.Extensions.DependencyInjection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Shiny.Extensions.DependencyInjection --version 1.0.3
                    
#r "nuget: Shiny.Extensions.DependencyInjection, 1.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Shiny.Extensions.DependencyInjection@1.0.3
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Shiny.Extensions.DependencyInjection&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Shiny.Extensions.DependencyInjection&version=1.0.3
                    
Install as a Cake Tool

Shiny Extensions

Dependency Injection Extensions

  • Source generate all attributed classes to a single add file - saves you the boilerplate
  • Extension methods for registering a dependency against multiple interfaces
  • Extension methods for startup tasks (different to hosted services that don't work on mobile)
  • Supports multiple interfaces
  • Supports open generics
  • Supports keyed services

The Results

THIS:

using Microsoft.Extensions.DependencyInjection;
using Shiny.Extensions.DependencyInjection;

// 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.Extensions.DependencyInjection;

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

  1. Install the NuGet package Shiny.Extensions.DependencyInjection
  2. Add the following using directive:
    // during your app startup - use your service collection 
    builder.Services.AddGeneratedServices();
    
  3. Add the [Service(ServiceLifetime.Singleton, "optional key")] attribute to your classes and specify the lifetime and optional key

Stores

  • Key/value store with support for
    • Android/iOS/Windows - Preferences & Secure Storage
    • Web - Local Storage & Session Storage
    • In Memory
  • Object binder binds INotifyPropertyChanged against a key/value store to persist object changes across sessions
  • Simply implement IKeyValueStore to create your own store

Setup

  1. Install the NuGet package Shiny.Extensions.Stores
  2. Add the following using directive:
// during your app startup - use your service collection 

builder.Services.AddPersistentService<MyNotifyPropertyChangedObject>("secure"); // optional: default to `settings`
  1. Inject the MyNotifyPropertyChangedObject into your view model or service. Set properties and they will be persisted automatically.
  2. To bypass reflection and make binding super fast - use Shiny Reflector to remove the need for reflection. It is already built into the Shiny.Extensions.Stores package, so you can use it directly. Just mark [Reflector] on your class and make your class partial.

Available Stores Per Platform

Platform Store Alias Description
Android settings Preferences store
Android secure Secure Storage
iOS settings Preferences store
iOS secure Secure Storage
WebAssembly settings Local Storage
WebAssembly session Session Storage
All Memory In Memory store - great for testing

For WebAssembly, install the Shiny.Extensions.Stores.Web package and add services.AddWebAssemblyStores() to your service collection.

Web Hosting Extensions

  • Merges service container build and post build scenarios into a single class
  • All IInfrastructureModule implementations are automatically detected and run

Setup

  1. Install the NuGet package Shiny.Extensions.WebHosting
  2. Add an infrastructure module by implementing IInfrastructureModule:
    using Shiny.Extensions.WebHosting;
    
    public class MyInfrastructureModule : IInfrastructureModule
    {
        public void Add(WebApplicationBuilder builder)
        {
            // Register your services here
        }
    
        public void Configure(WebApplication app)
        {
            // Configure your application here
        }
    }
    
  3. In your application hosting startup, add the following:
    using Shiny.Extensions.WebHosting;
    
    var builder = WebApplication.CreateBuilder(args);
    builder.AddInfrastructure(params Assembly[] assemblies)(); // this scans the assemblies for IInfrastructureModule implementations and runs Add methods
    // OR
    builder.AddInfrastructureModules(params IInfrastructureModule[] modules); // this doesn't use reflection
    
    var app = builder.Build();
    app.UseInfrastructure(); // this runs all IInfrastructureModule.Use methods
    

Additional Libraries Used

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

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
1.3.1 214 9/20/2025
1.3.1-beta-0001 200 9/20/2025
1.3.0 309 9/16/2025
1.3.0-beta-0009 149 8/11/2025
1.3.0-beta-0008 145 7/28/2025
1.3.0-beta-0007 141 7/28/2025
1.3.0-beta-0006 301 7/26/2025
1.3.0-beta-0004 498 7/24/2025
1.3.0-beta-0003 159 7/15/2025
1.3.0-beta-0002 156 7/15/2025
1.3.0-beta-0001 150 7/15/2025
1.2.2 171 7/28/2025
1.2.1 237 7/15/2025
1.2.0 154 7/15/2025
1.2.0-beta-0001 157 7/15/2025
1.1.0 165 7/13/2025
1.1.0-beta-0009 120 7/12/2025
1.1.0-beta-0008 92 7/11/2025
1.1.0-beta-0007 162 7/7/2025
1.1.0-beta-0006 163 7/6/2025
1.1.0-beta-0004 103 7/4/2025
1.1.0-beta-0003 112 7/4/2025
1.1.0-beta-0002 142 7/4/2025
1.0.3 153 7/7/2025
1.0.2 117 7/4/2025
1.0.1 146 7/4/2025
1.0.0 176 7/3/2025
1.0.0-g5fce6b880d 155 7/3/2025
1.0.0-alpha-0020 168 7/2/2025
1.0.0-alpha-0019 156 7/1/2025
1.0.0-alpha-0018 158 7/1/2025
1.0.0-alpha-0017 159 7/1/2025
1.0.0-alpha-0016 158 7/1/2025
1.0.0-alpha-0015 155 7/1/2025
1.0.0-alpha-0014 159 7/1/2025
1.0.0-alpha-0013 145 7/1/2025
1.0.0-alpha-0011 155 7/1/2025
1.0.0-alpha-0010 162 7/1/2025
1.0.0-alpha-0009 148 7/1/2025