Huvermann.Extensions.DependencyInjection 1.0.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Huvermann.Extensions.DependencyInjection --version 1.0.4
NuGet\Install-Package Huvermann.Extensions.DependencyInjection -Version 1.0.4
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="Huvermann.Extensions.DependencyInjection" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Huvermann.Extensions.DependencyInjection --version 1.0.4
#r "nuget: Huvermann.Extensions.DependencyInjection, 1.0.4"
#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.
// Install Huvermann.Extensions.DependencyInjection as a Cake Addin
#addin nuget:?package=Huvermann.Extensions.DependencyInjection&version=1.0.4

// Install Huvermann.Extensions.DependencyInjection as a Cake Tool
#tool nuget:?package=Huvermann.Extensions.DependencyInjection&version=1.0.4

Extensions.DependencyInjection

DI Factories

#Example of service registration:

Create a Startup where a Servicecollection is created.

"AddNamedServiceRegistration": extents the servicecollection for Named Services "AddModularity": extends the servicecollection to use all IRegistrationModule for service registration

 public class Startup
    {
        private readonly ServiceProvider _serviceProvider;

        public Startup()
        {
            IServiceCollection services = new ServiceCollection();
            ConfigureServices(services);
            _serviceProvider = services.BuildServiceProvider();

        }

        private IServiceCollection ConfigureServices(IServiceCollection services)
        {
            // Add the extension
            services.AddNamedServiceRegistration();

            // Add module registration
            services.AddModularity();

            
            return services;
        }

        public void Start()
        {
            var mainRunner = _serviceProvider.GetService<MainRunner>();
            mainRunner.Run();
        }
    }

#Use of IRegistrationModule

Every class that implements IRegistrationModule is automatically used as service registration


using Huvermann.Extensions.DependencyInjection.Abstractions.Modularity;
using Huvermann.Extensions.DependencyInjection.Abstractions.ServiceFactories;
using Huvermann.Extensions.DependencyInjection.ServiceFactories;
using Microsoft.Extensions.DependencyInjection;

namespace Huvermann.Extensions.DependencyInjection.Demo.Runner.Plugin
{
    public class PluginRegistration : IRegistrationModule
    {
        public void Configure(IServiceCollection services)
        {
            // Add all plugins by name
            services.AddTransientByName<IPlugin, PluginA>("NameA");
            services.AddTransientByName<IPlugin, PluginB>("NameIsB");

            // Add a Factory for the plugin interface
            services.AddTransient<IServiceByNameFactory<IPlugin>, ServiceByNameFactory<IPlugin>>();

            // Add a foo service factory.
            services.AddFactory<IFooService, Foo>();
            // The class, where all the stuff is used.
            services.AddTransient<MainRunner>();
        }
    }
}

Example of usage:

public class MainRunner
    {
        private IServiceByNameFactory<IPlugin> _pluginFactory;
        private IFactory<IFooService> _fooFactory;

        public MainRunner(IServiceByNameFactory<IPlugin> pluginFactory, IFactory<IFooService> fooFactory)
        {
            _pluginFactory = pluginFactory;
            _fooFactory = fooFactory;
        }

        public void Run()
        {
            var serviceWithNameA = _pluginFactory.GetServiceByName("NameA");
            Console.WriteLine("Got: " +serviceWithNameA.PluginName());
            var serviceWithNameB = _pluginFactory.GetServiceByName("NameIsB");
            Console.WriteLine("Got: " + serviceWithNameB.PluginName());

            Console.WriteLine("Resolve a foo class at runtime...");
            IFooService foo = _fooFactory.Create();
            foo.DoSomething();

            Console.WriteLine("Press any key.");
            Console.ReadLine();
        }
    }
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 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

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 408 8/3/2022
1.0.5 449 7/23/2020
1.0.4 446 10/21/2019
1.0.3 433 10/19/2019
1.0.2 422 10/19/2019
1.0.1 434 10/19/2019
1.0.0 430 10/19/2019

New: Modularity