Skip to content

Commit

Permalink
Add experimental attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchdenny committed Aug 12, 2024
1 parent f97f7c8 commit 7cc4263
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public class DistributedApplicationBuilder : IDistributedApplicationBuilder
public IResourceCollection Resources { get; } = new ResourceCollection();

/// <inheritdoc />
#pragma warning disable ASPIREEVENTING001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
public IDistributedApplicationEventing Eventing { get; } = new DistributedApplicationEventing();
#pragma warning restore ASPIREEVENTING001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

/// <summary>
/// Initializes a new instance of the <see cref="DistributedApplicationBuilder"/> class with the specified options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Eventing;
Expand All @@ -6,6 +7,7 @@ namespace Aspire.Hosting.Eventing;
/// Represents a subscription to an event that is published during the lifecycle of the AppHost.
/// </summary>
/// <param name="callback">Callback to invoke when the event is published.</param>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public class DistributedApplicationEventSubscription(Func<IDistributedApplicationEvent, CancellationToken, Task> callback)
{
/// <summary>
Expand All @@ -17,6 +19,7 @@ public class DistributedApplicationEventSubscription(Func<IDistributedApplicatio
/// <summary>
/// Represents a subscription to an event that is published during the lifecycle of the AppHost for a specific resource.
/// </summary>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public class DistributedApplicationResourceEventSubscription(IResource? resource, Func<IDistributedApplicationResourceEvent, CancellationToken, Task> callback)
: DistributedApplicationEventSubscription((@event, cancellationToken) => callback((IDistributedApplicationResourceEvent)@event, cancellationToken))
{
Expand Down
6 changes: 6 additions & 0 deletions src/Aspire.Hosting/Eventing/DistributedApplicationEventing.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Eventing;

/// <inheritdoc cref="IDistributedApplicationEventing" />
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public class DistributedApplicationEventing : IDistributedApplicationEventing
{
private readonly Dictionary<Type, List<DistributedApplicationEventSubscription>> _eventSubscriptionListLookup = new();
private readonly Dictionary<DistributedApplicationEventSubscription, Type> _subscriptionEventTypeLookup = new();

/// <inheritdoc cref="IDistributedApplicationEventing.PublishAsync{T}(T, CancellationToken)" />
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public async Task PublishAsync<T>(T @event, CancellationToken cancellationToken) where T : IDistributedApplicationEvent
{
if (_eventSubscriptionListLookup.TryGetValue(typeof(T), out var subscriptions))
Expand All @@ -24,6 +27,7 @@ public async Task PublishAsync<T>(T @event, CancellationToken cancellationToken)
}

/// <inheritdoc cref="IDistributedApplicationEventing.Subscribe{T}(Func{T, CancellationToken, Task})" />
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public DistributedApplicationEventSubscription Subscribe<T>(Func<T, CancellationToken, Task> callback) where T : IDistributedApplicationEvent
{
var subscription = new DistributedApplicationEventSubscription(async (@event, ct) =>
Expand All @@ -47,6 +51,7 @@ public DistributedApplicationEventSubscription Subscribe<T>(Func<T, Cancellation
}

/// <inheritdoc cref="IDistributedApplicationEventing.Subscribe{T}(Func{T, CancellationToken, Task})" />
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public DistributedApplicationEventSubscription Subscribe<T>(IResource resource, Func<T, CancellationToken, Task> callback) where T : IDistributedApplicationResourceEvent
{
var resourceFilteredCallback = async (T @event, CancellationToken cancellationToken) =>
Expand All @@ -61,6 +66,7 @@ public DistributedApplicationEventSubscription Subscribe<T>(IResource resource,
}

/// <inheritdoc cref="IDistributedApplicationEventing.Unsubscribe(DistributedApplicationEventSubscription)" />
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public void Unsubscribe(DistributedApplicationEventSubscription subscription)
{
if (_subscriptionEventTypeLookup.TryGetValue(subscription, out var eventType))
Expand Down
3 changes: 3 additions & 0 deletions src/Aspire.Hosting/Eventing/IDistributedApplicationEvent.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Eventing;

/// <summary>
/// Represents an event that is published during the lifecycle of the AppHost.
/// </summary>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public interface IDistributedApplicationEvent
{
}

/// <summary>
/// Represents an event that is published during the lifecycle of the AppHost for a specific resource.
/// </summary>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
public interface IDistributedApplicationResourceEvent : IDistributedApplicationEvent
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;

namespace Aspire.Hosting.Eventing;
Expand All @@ -13,6 +14,7 @@ public interface IDistributedApplicationEventing
/// <typeparam name="T">The type of the event.</typeparam>
/// <param name="callback">A callback to handle the event.</param>
/// <returns>A subscription instance which can be used to unsubscribe </returns>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
DistributedApplicationEventSubscription Subscribe<T>(Func<T, CancellationToken, Task> callback) where T : IDistributedApplicationEvent;

/// <summary>
Expand All @@ -22,12 +24,14 @@ public interface IDistributedApplicationEventing
/// <param name="resource">The resource instance associated with the event.</param>
/// <param name="callback">A callback to handle the event.</param>
/// <returns>A subscription instance which can be used to unsubscribe.</returns>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
DistributedApplicationEventSubscription Subscribe<T>(IResource resource, Func<T, CancellationToken, Task> callback) where T : IDistributedApplicationResourceEvent;

/// <summary>
/// Unsubscribe from an event.
/// </summary>
/// <param name="subscription">The specific subscription to unsubscribe.</param>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
void Unsubscribe(DistributedApplicationEventSubscription subscription);

/// <summary>
Expand All @@ -37,5 +41,6 @@ public interface IDistributedApplicationEventing
/// <param name="event">The event.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>A task that can be awaited.</returns>
[Experimental("ASPIREEVENTING001", UrlFormat = "https://aka.ms/dotnet/aspire/diagnostics#{0}")]
Task PublishAsync<T>(T @event, CancellationToken cancellationToken) where T : IDistributedApplicationEvent;
}
2 changes: 2 additions & 0 deletions tests/Aspire.Hosting.Tests/Dcp/ApplicationExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ private static ApplicationExecutor CreateAppExecutor(
configuration = builder.Build();
}

#pragma warning disable ASPIREEVENTING001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
return new ApplicationExecutor(
NullLogger<ApplicationExecutor>.Instance,
NullLogger<DistributedApplication>.Instance,
Expand All @@ -764,6 +765,7 @@ private static ApplicationExecutor CreateAppExecutor(
new DistributedApplicationEventing(),
serviceProvider
);
#pragma warning restore ASPIREEVENTING001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
}

private sealed class TestHostApplicationLifetime : IHostApplicationLifetime
Expand Down

0 comments on commit 7cc4263

Please sign in to comment.