.NET 开发常用技巧 依赖注入123456789101112// 注册服务services.AddScoped<IMyService, MyService>();// 构造函数注入public class MyController : Controller{ private readonly IMyService _service; public MyController(IMyService service) { _service = service; }} SqlSugar 常用操作123456789// 查询var list = await db.Queryable<Order>() .Where(x => x.Status == 1) .OrderByDescending(x => x.CreateTime) .ToListAsync();// 分页var page = await db.Queryable<Order>() .ToPageIndexListAsync(pageIndex, pageSize); 异步编程123456// 避免 async voidpublic async Task DoSomethingAsync(){ await Task.Delay(1000); Console.WriteLine("Done");} 配置管理123456// 读取配置var value = configuration["Section:Key"];// 强类型绑定services.Configure<AppSettings>( configuration.GetSection("AppSettings")); 技术 > 后端 #dotnet #csharp #sqlsugar .NET 开发常用技巧 https://dominator.abrdns.com/2026/06/28/dotnet-tips/ 发布于 2026年6月28日 许可协议 CC BY-NC-SA 4.0 Git 常用命令速查表 上一篇 悲惨的恋爱故事——现世报 下一篇