TryAtSoftware.Extensions.DependencyInjection.Standard
1.1.2-alpha.1
Prefix Reserved
See the version list below for details.
dotnet add package TryAtSoftware.Extensions.DependencyInjection.Standard --version 1.1.2-alpha.1
NuGet\Install-Package TryAtSoftware.Extensions.DependencyInjection.Standard -Version 1.1.2-alpha.1
<PackageReference Include="TryAtSoftware.Extensions.DependencyInjection.Standard" Version="1.1.2-alpha.1" />
paket add TryAtSoftware.Extensions.DependencyInjection.Standard --version 1.1.2-alpha.1
#r "nuget: TryAtSoftware.Extensions.DependencyInjection.Standard, 1.1.2-alpha.1"
// Install TryAtSoftware.Extensions.DependencyInjection.Standard as a Cake Addin #addin nuget:?package=TryAtSoftware.Extensions.DependencyInjection.Standard&version=1.1.2-alpha.1&prerelease // Install TryAtSoftware.Extensions.DependencyInjection.Standard as a Cake Tool #tool nuget:?package=TryAtSoftware.Extensions.DependencyInjection.Standard&version=1.1.2-alpha.1&prerelease
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.
It accepts a single required parameter - the ServiceLifetime
.
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 theAutomaticallyRegisteredService
andServiceConfiguration
attributes if additional configurations are required.
[AutomaticallyRegisteredService, ServiceConfiguration(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 theServiceConfiguration
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:
- Resolve generic parameters.
- Discover additional configurations (using the hierarchy scanner).
- Register the service (within the service collection).
- At least one service descriptor will always be registered. It will have its
ServiceType
andImplementationType
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.
- At least one service descriptor will always be registered. It will have its
IServiceCollection serviceCollection = new ServiceCollection();
IHierarchyScanner hierarchyScanner = new HierarchyScanner();
IServiceRegistrar registrar = new ServiceRegistrar(serviceCollection, hierarchyScanner);
Assembly[] allAssemblies = AppDomain.CurrentDomain.GetAssemblies();
allAssemblies.AutoRegisterServices(serviceRegistrar);
Helpful Links
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 | Versions 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 | 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. |
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.1)
- TryAtSoftware.Extensions.DependencyInjection (>= 1.1.2-alpha.1)
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 | 214 | 11/15/2023 |
1.1.2-alpha.1 | 117 | 7/22/2023 |