IServiceCollection
-
[.NET] IServiceCollection기반 서비스에 args 값 의존성 주입(DI) 간단히 처리하기.NET/개념 및 유용한 팁 2022. 8. 3. 22:03
간혹 콘솔프로그램의 args를 IServiceCollection 및 Builder로 구성된 ASP.NET Core 및 Worker 에 그대로 의존성 주입하고 싶을때가 있다. 방법은 간단한다. AddSingleton(args); 한줄이면 끝난다. 아래코드는 .NET 6기반의 ASP.NET Core WebApi 프로젝트이다. [Program.cs] var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuc..