![]() |
VOOZH | about |
dotnet add package Encamina.Enmarcha.DependencyInjection --version 10.0.5
NuGet\Install-Package Encamina.Enmarcha.DependencyInjection -Version 10.0.5
<PackageReference Include="Encamina.Enmarcha.DependencyInjection" Version="10.0.5" />
<PackageVersion Include="Encamina.Enmarcha.DependencyInjection" Version="10.0.5" />Directory.Packages.props
<PackageReference Include="Encamina.Enmarcha.DependencyInjection" />Project file
paket add Encamina.Enmarcha.DependencyInjection --version 10.0.5
#r "nuget: Encamina.Enmarcha.DependencyInjection, 10.0.5"
#:package Encamina.Enmarcha.DependencyInjection@10.0.5
#addin nuget:?package=Encamina.Enmarcha.DependencyInjection&version=10.0.5Install as a Cake Addin
#tool nuget:?package=Encamina.Enmarcha.DependencyInjection&version=10.0.5Install as a Cake Tool
This project contains functionalities related to dependency injection. It primarily includes extension methods to simplify and enhance the capabilities of Microsoft.Extensions.DependencyInjection.
First, install NuGet. Then, install Encamina.Enmarcha.DependencyInjection from the package manager console:
PM> Install-Package Encamina.Enmarcha.DependencyInjection
First, install .NET CLI. Then, install Encamina.Enmarcha.DependencyInjection from the .NET CLI:
dotnet add package Encamina.Enmarcha.DependencyInjection
You can use the attribute for your types, which enables automatic registration of themselves into the dependency injection container.
public interface IFoo
{
void SayFoo();
}
[AutoRegisterService(ServiceLifetime.Singleton)]
public class ConsoleFoo : IFoo
{
public void SayFoo()
{
Console.WriteLine("Foo");
}
}
and a Program.cs or a similar entry point file in your project, add the following code:
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
// ...
});
// ...
builder.Services.AddAutoRegisterServicesFromAssembly<Program>();
The above code adds types decorated with the AutoRegisterServiceAttribute (such as FooBar) into the service collection from the Program assembly.
With this, it can resolve the IFoo class with construction injection.
public class MyClass
{
private readonly IFoo foo;
public MyClass(IFoo foo)
{
this.foo = foo;
}
public void TestFoo()
{
foo.SayFoo();
}
}
or Service Provider
var serviceProvider = services.BuildServiceProvider();
var foo = serviceProvider.GetRequiredService<IFoo>();
foo.SayFoo();
You can configure the ServiceLifetime to be Singleton, Scoped, or Transient.
public interface IFoo
{
void SayFoo();
}
// Registers ConsoleFoo as Scoped
[AutoRegisterService(ServiceLifetime.Scoped)]
public class ConsoleFoo : IFoo
{
public void SayFoo()
{
Console.WriteLine("Foo");
}
}
You can specify the alternative types with which the class will be registered.
public interface IFoo
{
void SayFoo();
}
public class ConsoleFooBar : IFoo
{
public virtual void SayFoo()
{
Console.WriteLine("Foo");
}
}
[AutoRegisterService(ServiceLifetime.Scoped, typeof(ConsoleFooBar), typeof(IFoo))]
public class RedConsoleFooBar : ConsoleFooBar
{
public override void SayFoo()
{
Console.ForegroundColor = ConsoleColor.Red;
base.SayFoo();
Console.ResetColor();
}
}
In the above code, it specifies that RedConsoleFooBar should register the alternative types ConsoleFooBar and IFoo. This means that when you resolve an instance of type RedConsoleFooBar, ConsoleFooBar, or IFoo, it will be resolved as RedConsoleFooBar.
// ...
var foo = builder.Services.BuildServiceProvider().GetRequiredService<IFoo>();
var consoleFooBar = builder.Services.BuildServiceProvider().GetRequiredService<ConsoleFooBar>();
var redConsoleFooBar = builder.Services.BuildServiceProvider().GetRequiredService<RedConsoleFooBar>();
bool fooIsRedConsoleFooBar = foo.GetType() == typeof(RedConsoleFooBar); // Is true
bool consoleFooBarIsRedConsoleFooBar = consoleFooBar.GetType() == typeof(RedConsoleFooBar); // Is true
bool fooRedConsoleFooBarIsRedConsoleFooBar = redConsoleFooBar.GetType() == typeof(RedConsoleFooBar); // Is true
There are some scenarios when a class should be registered only as an implementation type, regardless the interfaces it implements. For this scenarios, sets ForceOnlyAsImplementationType to true.
public interface IFoo
{
void SayFoo();
}
[AutoRegisterService(ServiceLifetime.Scoped, ForceOnlyAsImplementationType = true)]
public class ConsoleFooBar : IFoo
{
public void SayFoo()
{
Console.WriteLine("Foo");
}
}
Now, you can only resolve ConsoleFooBar directly using the class itself (ConsoleFooBar); attempting to resolve it through its interface will throw an exception.
// ...
// Throws System.InvalidOperationException: 'No service for type 'IFoo' has been registered.'
var foo = builder.Services.BuildServiceProvider().GetRequiredService<IFoo>();
// It's OK
var consoleFooBar = builder.Services.BuildServiceProvider().GetRequiredService<ConsoleFooBar>();
Set RegisterInterfaces to false when the interfaces directly implemented by the class should not be registered as service types.
public interface IFoo
{
void SayFoo();
}
[AutoRegisterService(ServiceLifetime.Scoped, RegisterInterfaces = false)]
public class ConsoleFooBar : IFoo
{
public void SayFoo()
{
Console.WriteLine("Foo");
}
}
Now, when attempting to resolve IFoo directly, an exception will be thrown.
// ...
// Throws System.InvalidOperationException: 'No service for type 'IFoo' has been registered.'
var foo = builder.Services.BuildServiceProvider().GetRequiredService<IFoo>();
// It's OK
var consoleFooBar = builder.Services.BuildServiceProvider().GetRequiredService<ConsoleFooBar>();
Set IncludeInheritedInterfaces to true when the interfaces inherited by the class (i.e., implemented by base classes) should be registered as services types.
public interface IFoo
{
void SayFoo();
}
public class ConsoleBaseFooBar : IFoo
{
public virtual void SayFoo()
{
Console.WriteLine("Foo");
}
}
[AutoRegisterService(ServiceLifetime.Scoped, IncludeInheritedInterfaces = true)]
public class RedConsoleFooBar : ConsoleBaseFooBar
{
public override void SayFoo()
{
Console.ForegroundColor = ConsoleColor.Red;
base.SayFoo();
Console.ResetColor();
}
}
Even though RedConsoleFooBar does not explicitly specify that it implements IFoo, since its base class ConsoleBaseFooBar implements it, you can resolve IFoo directly.
// ...
// It's OK
var foo = builder.Services.BuildServiceProvider().GetRequiredService<IFoo>();
You can directly register a type or type/implementation by specifying the ServiceLifetime.
public interface IFoo
{
void SayFoo();
}
public class ConsoleFooBar : IFoo
{
public virtual void SayFoo()
{
Console.WriteLine("Foo");
}
}
Next, in Program.cs or a similar entry point file in your project, add the following code.
// Register by type
builder.Services.AddType<ConsoleFooBar>(ServiceLifetime.Singleton);
builder.Services.TryAddType<ConsoleFooBar>(ServiceLifetime.Singleton);
// or TService, TImplementation
builder.Services.AddType<IFoo, ConsoleFooBar>(ServiceLifetime.Singleton);
builder.Services.TryAddType<IFoo, ConsoleFooBar>(ServiceLifetime.Singleton);
// or with implementation Instance
builder.Services.TryAddType<IFoo>(ServiceLifetime.Singleton, new ConsoleFooBar());
// or with factory method
builder.Services.TryAddType<IFoo, ConsoleFooBar>(ServiceLifetime.Singleton, provider => new ConsoleFooBar(provider.GetRequiredService<IDependency>()));
// ... the TryAddType and AddType methods can be used in various flavors to register services into an IServiceCollection.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 netstandard2.1 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Encamina.Enmarcha.DependencyInjection:
| Package | Downloads |
|---|---|
|
Encamina.Enmarcha.Bot
Package Description |
|
|
Encamina.Enmarcha.SemanticKernel.Connectors.Memory
Package Description |
|
|
Encamina.Enmarcha.SemanticKernel.Connectors.Document
Package Description |
|
|
Encamina.Enmarcha.Email.MailKit
Package Description |
|
|
Encamina.Enmarcha.Conversation
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.0.5 | 358 | 6/1/2026 |
| 10.0.4 | 680 | 4/8/2026 |
| 10.0.3 | 946 | 4/6/2026 |
| 10.0.2 | 1,537 | 12/17/2025 |
| 10.0.1 | 409 | 12/17/2025 |
| 10.0.0 | 420 | 12/16/2025 |
| 10.0.0-preview-09 | 582 | 11/19/2025 |
| 10.0.0-preview-08 | 572 | 11/18/2025 |
| 10.0.0-preview-07 | 860 | 10/22/2025 |
| 10.0.0-preview-06 | 1,009 | 10/14/2025 |
| 10.0.0-preview-05 | 353 | 10/8/2025 |
| 10.0.0-preview-04 | 348 | 10/7/2025 |
| 10.0.0-preview-03 | 482 | 9/16/2025 |
| 10.0.0-preview-02 | 478 | 9/16/2025 |
| 8.3.0 | 1,416 | 9/10/2025 |
| 8.3.0-preview-02 | 400 | 9/10/2025 |
| 8.3.0-preview-01 | 426 | 9/8/2025 |
| 8.2.1-preview-08 | 418 | 8/18/2025 |
| 8.2.1-preview-07 | 406 | 8/12/2025 |