From 94fd036c0008377f441d71305c39bda1d7282768 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=9B=90?= Date: Wed, 17 Jul 2024 17:27:17 +0900 Subject: [PATCH] DI supports trimming like : https://github.com/dotnet/runtime/blob/138cb59cd53eeb7775b6d2a11c80f70dfef3a2df/src/libraries/Microsoft.Extensions.DependencyInjection.Abstractions/src/ServiceCollectionServiceExtensions.cs#L68 --- .../CoconaLiteServiceCollectionExtensions.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Cocona.Lite/Lite/CoconaLiteServiceCollectionExtensions.cs b/src/Cocona.Lite/Lite/CoconaLiteServiceCollectionExtensions.cs index 8a8b5d0..c8673b5 100644 --- a/src/Cocona.Lite/Lite/CoconaLiteServiceCollectionExtensions.cs +++ b/src/Cocona.Lite/Lite/CoconaLiteServiceCollectionExtensions.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; + namespace Cocona.Lite; public static class CoconaLiteServiceCollectionExtensions @@ -26,7 +28,11 @@ public static void AddTransient(this ICoconaLiteServiceCollection serv }, singleton: false); } - public static void AddTransient(this ICoconaLiteServiceCollection services) + public static void AddTransient(this ICoconaLiteServiceCollection services) where TImplementation : TService { services.AddDescriptor((provider, disposables) => @@ -41,7 +47,11 @@ public static void AddTransient(this ICoconaLiteServi }, singleton: false); } - public static void AddSingleton(this ICoconaLiteServiceCollection services) + public static void AddSingleton(this ICoconaLiteServiceCollection services) where TImplementation : TService { services.AddDescriptor((provider, disposables) => @@ -82,7 +92,11 @@ public static void TryAddTransient(this ICoconaLiteServiceCollection s } } - public static void TryAddTransient(this ICoconaLiteServiceCollection services) + public static void TryAddTransient(this ICoconaLiteServiceCollection services) where TImplementation : TService { if (services.All(x => x.ServiceType != typeof(TService))) @@ -91,7 +105,11 @@ public static void TryAddTransient(this ICoconaLiteSe } } - public static void TryAddSingleton(this ICoconaLiteServiceCollection services) + public static void TryAddSingleton(this ICoconaLiteServiceCollection services) where TImplementation : TService { if (services.All(x => x.ServiceType != typeof(TService)))