Kotz.DependencyInjection 2.2.0-nightly-042

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

// Install Kotz.DependencyInjection as a Cake Tool
#tool nuget:?package=Kotz.DependencyInjection&version=2.2.0-nightly-042&prerelease                

Kotz.DependencyInjection

  • Dependencies:
    • Microsoft.Extensions.DependencyInjection.Abstractions

Defines the following extension methods:

  • IServiceCollection Extensions
    • RegisterServices: Registers all classes and structs from an assembly that have a ServiceAttributeBase applied to them.
  • IServiceProvider and IServiceScopeFactory Extensions
    • GetParameterizedService: Gets a service that requires arguments that are not registered in the IoC container.
    • GetScopedService: Gets a service that needs to be resolved from a scope.

Defines the following types:

  • ServiceAttributeBase: It's the base class for dependency injection registrations.
  • ServiceAttribute: Marks a class or struct for registration via the IServiceCollection.RegisterServices extension method.
  • ServiceAttribute<T>: Marks a class or struct for registration under the type T via the IServiceCollection.RegisterServices extension method.

How to use the attributes

  1. Registering the type directly
// Registration.
[Service(ServiceLifetime.Singleton)]
public sealed class MyService { ... }

// Resolution.
serviceProvider.GetRequiredService<MyService>();
  1. Registering the type through another type.
// Registration.
[Service<ISomething>(ServiceLifetime.Scoped)]
public sealed class MyService : ISomething { ... }

// Resolution.
serviceProvider.GetRequiredService<ISomething>();
  1. Registering multiple types under the same type.
[Service<ISomething>(ServiceLifetime.Transient, true)]
public sealed class MyService1 : ISomething { ... }

[Service<ISomething>(ServiceLifetime.Transient, true)]
public sealed class MyService2 : ISomething { ... }

[Service<ISomething>(ServiceLifetime.Transient, true)]
public sealed class MyService3 : ISomething { ... }
  1. Registering the services in the IServiceCollection.
// To register services from the current assembly.
serviceCollection.RegisterServices();

// OR

// To register services from a specific assembly.
serviceCollection.RegisterServices(assembly);
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Kotz.DependencyInjection:

Package Downloads
Kotz.Utilities

Provides utility types and methods for common tasks. This is a metapackage that includes all Kotz utility packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.3-nightly-075 74 5/25/2024
2.3.2 85 5/25/2024
2.3.1 86 5/25/2024
2.3.0 88 5/24/2024
2.3.0-nightly-070 77 5/24/2024
2.3.0-nightly-069 74 5/24/2024
2.3.0-nightly-068 73 5/24/2024
2.3.0-nightly-067 77 5/24/2024
2.3.0-nightly-066 81 5/24/2024
2.3.0-nightly-065 78 5/23/2024
2.3.0-nightly-064 76 5/23/2024
2.3.0-nightly-062 57 5/16/2024
2.2.2-nightly-059 89 4/16/2024
2.2.2-nightly-058 76 4/10/2024
2.2.2-nightly-057 77 4/9/2024
2.2.2-nightly-056 76 4/4/2024
2.2.1 148 3/21/2024
2.2.1-nightly-054 55 3/21/2024
2.2.1-nightly-053 78 3/20/2024
2.2.1-nightly-051 79 3/16/2024
2.2.0 176 12/17/2023
2.2.0-nightly-049 88 12/23/2023
2.2.0-nightly-048 113 12/17/2023
2.2.0-nightly-042 116 9/23/2023
2.2.0-nightly-041 99 9/23/2023
2.2.0-nightly-039 99 9/23/2023