Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI supports Aot | trimming #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/Cocona.Lite/Lite/CoconaLiteServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics.CodeAnalysis;

namespace Cocona.Lite;

public static class CoconaLiteServiceCollectionExtensions
Expand Down Expand Up @@ -26,7 +28,11 @@ public static void AddTransient<TService>(this ICoconaLiteServiceCollection serv
}, singleton: false);
}

public static void AddTransient<TService, TImplementation>(this ICoconaLiteServiceCollection services)
public static void AddTransient<TService,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
TImplementation>(this ICoconaLiteServiceCollection services)
where TImplementation : TService
{
services.AddDescriptor<TService>((provider, disposables) =>
Expand All @@ -41,7 +47,11 @@ public static void AddTransient<TService, TImplementation>(this ICoconaLiteServi
}, singleton: false);
}

public static void AddSingleton<TService, TImplementation>(this ICoconaLiteServiceCollection services)
public static void AddSingleton<TService,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
TImplementation>(this ICoconaLiteServiceCollection services)
where TImplementation : TService
{
services.AddDescriptor<TService>((provider, disposables) =>
Expand Down Expand Up @@ -82,7 +92,11 @@ public static void TryAddTransient<TService>(this ICoconaLiteServiceCollection s
}
}

public static void TryAddTransient<TService, TImplementation>(this ICoconaLiteServiceCollection services)
public static void TryAddTransient<TService,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
TImplementation>(this ICoconaLiteServiceCollection services)
where TImplementation : TService
{
if (services.All(x => x.ServiceType != typeof(TService)))
Expand All @@ -91,7 +105,11 @@ public static void TryAddTransient<TService, TImplementation>(this ICoconaLiteSe
}
}

public static void TryAddSingleton<TService, TImplementation>(this ICoconaLiteServiceCollection services)
public static void TryAddSingleton<TService,
#if NET6_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
TImplementation>(this ICoconaLiteServiceCollection services)
where TImplementation : TService
{
if (services.All(x => x.ServiceType != typeof(TService)))
Expand Down