DependencyInjection.Autowired
Expand native dependency injection with property and field injection
Install / Use
/learn @Antelcat/DependencyInjection.AutowiredREADME
Antelcat.DependencyInjection.Autowired
Extensions of native .NET dependency injection with Autowired, provides a way to support properties and fields injection.
All lifetimes and generics are now supported. And using ILGeneratorEx to speed up the setter.
Usage
public class Service{
[Autowired]
private readonly IService dependency;
[Autowired]
private IService Dependency { get; set; }
}
In common :
IServiceProvider provider = new ServiceCollection()
.Add(...)
.BuildAutowiredServiceProvider(static x=>x.BuildServiceProvider());
IService service = provider.GetService<IService>();
In ASP.NET CORE MVC :
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers() //register controllers
.AddControllersAsServices() // add controllers as services
.UseAutowiredControllers(); // use auto wired controllers
builder.Host.UseAutowiredServiceProviderFactory(); // autowired services
Tests could be found in ServiceTest.cs , which shows higher performance than Autofac and is close to native.
Migration
Meanwhile, you can still use your attribute, only need to provide it at build time :
IServiceProvider provider = collection.BuildAutowiredServiceProvider<YourAutowiredAttribute>(...);
builder.Services.AddControllers()
.AddControllersAsServices()
.UseAutowiredControllers<YourAutowiredAttribute>();
builder.Host.UseAutowiredServiceProviderFactory<YourAutowiredAttribute>();
Related Skills
node-connect
352.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
