TryAtSoftware.Extensions.DependencyInjection.Standard 1.1.2

Prefix Reserved
dotnet add package TryAtSoftware.Extensions.DependencyInjection.Standard --version 1.1.2                
NuGet\Install-Package TryAtSoftware.Extensions.DependencyInjection.Standard -Version 1.1.2                
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="TryAtSoftware.Extensions.DependencyInjection.Standard" Version="1.1.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TryAtSoftware.Extensions.DependencyInjection.Standard --version 1.1.2                
#r "nuget: TryAtSoftware.Extensions.DependencyInjection.Standard, 1.1.2"                
#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 TryAtSoftware.Extensions.DependencyInjection.Standard as a Cake Addin
#addin nuget:?package=TryAtSoftware.Extensions.DependencyInjection.Standard&version=1.1.2

// Install TryAtSoftware.Extensions.DependencyInjection.Standard as a Cake Tool
#tool nuget:?package=TryAtSoftware.Extensions.DependencyInjection.Standard&version=1.1.2                

Quality Gate Status Reliability Rating Security Rating Maintainability Rating Vulnerabilities Bugs

Core validation

About the project

TryAtSoftware.Extensions.DependencyInjection.Standard is a library that extends TryAtSoftware.Extensions.DependencyInjection and operates with the built-in dependency injection mechanisms.

About us

Try At Software is a software development company based in Bulgaria. We are mainly using dotnet technologies (C#, ASP.NET Core, Entity Framework Core, etc.) and our main idea is to provide a set of tools that can simplify the majority of work a developer does on a daily basis.

Getting started

Installing the package

In order to use this library, you need to install the corresponding NuGet package beforehand. The simplest way to do this is to either use the NuGet package manager, or the dotnet CLI.

Using the NuGet package manager console within Visual Studio, you can install the package using the following command:

Install-Package TryAtSoftware.Extensions.DependencyInjection.Standard

Or using the dotnet CLI from a terminal window:

dotnet add package TryAtSoftware.Extensions.DependencyInjection.Standard

Registering services

Basic understanding of the concepts introduced by TryAtSoftware.Extensions.DependencyInjection is required. This package implements the presented ideas for the built-in dependency injection mechanisms.

Service configuration

This package extends the configuration mechanisms introduced by TryAtSoftware.Extensions.DependencyInjection and goes a step further by defining its own set of configuration options modeling the parameters (or behavior) applied to the registration process when operating with the built-in dependency injection container.

One of the most important characteristics for services registered in the built-in dependency injection container is their lifetime. So it looks like this parameter should be easily configurable when the corresponding services are automatically registered.

In the context of TryAtSoftware.Extensions.DependencyInjection.Standard, this can be achieved by decorating the service with the ServiceConfiguration attribute.

  • The Lifetime property can be used to control the ServiceLifetime used when registering the services - it is optional and its default is ServiceLifetime.Scoped.

As noted before, this package does not alter the configuration mechanisms introduced by TryAtSoftware.Extensions.DependencyInjection - it extends them. Because of this, it is required to decorate your services with both the AutomaticallyRegisteredService and ServiceConfiguration attributes if additional configurations are required.

[AutomaticallyRegisteredService, ServiceConfiguration(Lifetime = ServiceLifetime.Transient)]
public class EmailSender : IEmailSender
{
    // Here goes the implementation of the email sender... 
}

If a service should be registered automatically, but there are no explicit configurations, it will be registered as scoped service by default.

[AutomaticallyRegisteredService] // There are no explicit configurations => the lifetime of this service will be scoped.
public class EmailSender : IEmailSender
{
    // Here goes the implementation of the email sender... 
}

ServiceRegistrar

This class implements the IServiceRegistrar interface. Its only constructor accepts two parameters:

  • An IServiceCollection instance where the services will be registered.
  • An IHierarchyScanner instance used to scan for the ServiceConfiguration attribute described above. You can use this parameter if you need to customize the way configuration attributes are discovered.

This IServiceRegistrar implementation realizes all generally applicable use cases.

The registration process for any service involves the following steps:

  1. Resolve generic parameters.
  2. Discover additional configurations (using the hierarchy scanner).
  3. Register the service (within the service collection).
    • At least one service descriptor will always be registered. It will have its ServiceType and ImplementationType set to the type of the automatically registered service.
    • For each interface the service implements, another service descriptor will be registered as well. In this case, its ServiceType will be set to the type of the implemented interface.
IServiceCollection serviceCollection = new ServiceCollection();
IHierarchyScanner hierarchyScanner = new HierarchyScanner();
IServiceRegistrar registrar = new ServiceRegistrar(serviceCollection, hierarchyScanner);

Assembly[] allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
allAssemblies.AutoRegisterServices(registrar);

For a better understanding of the ideas implemented by this package, you can refer to the official documentation of TryAtSoftware.Extensions.DependencyInjection.

For a better understanding of the way the built-in dependency injection mechanisms work, you can refer to the official documentation. Here are some more links pointing to the corresponding packages - Microsoft.Extensions.DependencyInjection.Abstractions and Microsoft.Extensions.DependencyInjection.

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 is compatible.  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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.1.2 210 11/15/2023
1.1.2-alpha.1 117 7/22/2023