-
Notifications
You must be signed in to change notification settings - Fork 351
/
ManifestPublishingCallbackAnnotation.cs
48 lines (42 loc) · 1.93 KB
/
ManifestPublishingCallbackAnnotation.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.Publishing;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// Represents an annotation that provides a callback to be executed during manifest publishing.
/// </summary>
public class ManifestPublishingCallbackAnnotation : IResourceAnnotation
{
/// <summary>
/// Initializes a new instance of the <see cref="ManifestPublishingCallbackAnnotation"/> class with the specified callback.
/// </summary>
/// <param name="callback">A callback which provides access to <see cref="ManifestPublishingContext"/> which can be used for controlling JSON output into the manifest.</param>
public ManifestPublishingCallbackAnnotation(Action<ManifestPublishingContext>? callback)
{
if (callback is not null)
{
Callback = context =>
{
callback(context);
return Task.CompletedTask;
};
}
}
/// <summary>
/// Initializes a new instance of the <see cref="ManifestPublishingCallbackAnnotation"/> class with the specified callback.
/// </summary>
/// <param name="callback">A callback which provides access to <see cref="ManifestPublishingContext"/> which can be used for controlling JSON output into the manifest.</param>
public ManifestPublishingCallbackAnnotation(Func<ManifestPublishingContext, Task>? callback)
{
Callback = callback;
}
/// <summary>
/// Gets the callback action for publishing the manifest.
/// </summary>
public Func<ManifestPublishingContext, Task>? Callback { get; }
/// <summary>
/// Represents a <see langword="null"/>-based callback annotation for manifest
/// publishing used in scenarios where it's ignored.
/// </summary>
public static ManifestPublishingCallbackAnnotation Ignore { get; } = new(null);
}