🧩 HG.EasyDi is a lightweight dependency injection library for ASP.NET Core.
✨ Easy integration with ASP.NET Core applications.
✨ Attribute-based service registration.
✨ Support for singleton, scoped, and transient lifetimes.
✨ Automatic scanning of namespaces for service registration.
You can install the HG.EasyDi package via NuGet package manager or by adding it directly to your project file.
dotnet add package HG.EasyDi
Define your services and interfaces:
public interface ISampleService
{
void DoSomething();
}
[EasyDi(ServiceLifetime.Singleton)]
public class SampleService : ISampleService
{
public void DoSomething()
{
// Implementation code here
}
}
For register service as Lazy Proxy use :
[EasyDi(ServiceLifetime.Singleton, true)]
or
[LazyDi(ServiceLifetime.Singleton)]
Register services in your Program.cs file:
Full Scan:
builder.Services.AddEasyDi();
Scan special namespace:
builder.Services.AddEasyDi(o=>o.SetNamespaceRootToScan("HG.EasyDi.PlantTest.Service"));
Inject and use the services in your controllers or other classes:
public class SampleController : ControllerBase
{
private readonly ISampleService _sampleService;
public SampleController(ISampleService sampleService)
{
_sampleService = sampleService;
}
// Controller actions
}
Contributions are welcome! If you find a bug or have a feature suggestion, please open an issue on the GitHub repository.
This project is licensed under the MIT License.