# DYH.Extensions.DependencyInjection **Repository Path**: giteezxk/dyh.-extensions.-dependency-injection ## Basic Information - **Project Name**: DYH.Extensions.DependencyInjection - **Description**: 一个简单的依赖注入的库 - **Primary Language**: C# - **License**: MIT - **Default Branch**: v2.0 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 3 - **Created**: 2025-04-12 - **Last Updated**: 2025-04-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README [Nuget地址](https://www.nuget.org/packages/DYH.Extensions.DependencyInjection/) | [English Document](README_EnUs.md) # 简单说明 ## 在类上添加特性 ``` [TransientDI] public class MyTransientClass { } ``` ## 如果要注入接口则在参数中添加接口类型 ``` public interface IMyService { } [SingletonDI(typeof(IMyService))] public class MyService: IMyService { } ``` ## 程序启动时初始化 ``` var builder = new ServiceCollection(); builder.SetUpDependencyInjection() .AddAssembly([Assembly.GetExecutingAssembly()]) .BeginInject(); var serviceProvider = builder.BuildServiceProvider(); ```