Skip to content

Commit c033c9c

Browse files
committed
Added AOT compatibility to IStartupTask's.
1 parent 2b1513d commit c033c9c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Hosting/src/AppCoreNet.Extensions.Hosting.Abstractions/StartupTaskServiceCollectionExtensions.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright (c) The AppCore .NET project.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using AppCoreNet.Diagnostics;
67
using AppCoreNet.Extensions.Hosting;
78
using Microsoft.Extensions.DependencyInjection;
@@ -22,13 +23,14 @@ public static class StartupTaskServiceCollectionExtensions
2223
/// <param name="startupTaskType">The implementation of the <see cref="IStartupTask"/>.</param>
2324
/// <returns>The passed <see cref="IServiceCollection"/> to allow chaining.</returns>
2425
/// <exception cref="ArgumentNullException">Argument <paramref name="startupTaskType"/> is <c>null</c>.</exception>
25-
public static IServiceCollection AddStartupTask(this IServiceCollection services, Type startupTaskType)
26+
public static IServiceCollection AddStartupTask(
27+
this IServiceCollection services,
28+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type startupTaskType)
2629
{
2730
Ensure.Arg.NotNull(startupTaskType);
2831
Ensure.Arg.OfType<IStartupTask>(startupTaskType);
2932

3033
services.TryAddEnumerable(ServiceDescriptor.Transient(typeof(IStartupTask), startupTaskType));
31-
3234
return services;
3335
}
3436

@@ -38,7 +40,9 @@ public static IServiceCollection AddStartupTask(this IServiceCollection services
3840
/// <typeparam name="T">The implementation of the <see cref="IStartupTask"/>.</typeparam>
3941
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
4042
/// <returns>The passed <see cref="IServiceCollection"/> to allow chaining.</returns>
41-
public static IServiceCollection AddStartupTask<T>(this IServiceCollection services)
43+
public static IServiceCollection AddStartupTask<
44+
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] T>(
45+
this IServiceCollection services)
4246
where T : IStartupTask
4347
{
4448
return AddStartupTask(services, typeof(T));
@@ -50,7 +54,9 @@ public static IServiceCollection AddStartupTask<T>(this IServiceCollection servi
5054
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
5155
/// <param name="configure">The configuration delegate.</param>
5256
/// <returns>The passed <see cref="IServiceCollection"/> to allow chaining.</returns>
53-
public static IServiceCollection AddStartupTasksFrom(this IServiceCollection services, Action<IServiceDescriptorReflectionBuilder> configure)
57+
public static IServiceCollection AddStartupTasksFrom(
58+
this IServiceCollection services,
59+
Action<IServiceDescriptorReflectionBuilder> configure)
5460
{
5561
return services.TryAddEnumerableFrom<IStartupTask>(configure);
5662
}

Hosting/src/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<PropertyGroup>
55
<GenerateDocumentationFile>true</GenerateDocumentationFile>
6+
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsAotCompatible>
67
</PropertyGroup>
78

89
<ItemGroup>

0 commit comments

Comments
 (0)