Skip to content

Subscribing to interface or base class in IDistributedApplicationEventing #5565

@afscrome

Description

@afscrome

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In order to better understand what events were available, I tried to subscribe to all events by subscribing to IDistributedApplicationEvent. However I ended up subscribing to nothing.

My reasoning for trying to subscribe to everything was to try and get an idea of what events were being fired and when.

Expected Behavior

I was hoping to subscribe all events

Alternatively if the expectation was that you'd always subscribe to a concrete event, I would have hoped that trying to subscribe to an interface would have been blocked at subscription time - either by throwing an error if T is an interface or abstract class, or possibly through a generic constraint like where T : class

Steps To Reproduce

#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.
builder.Eventing.Subscribe<IDistributedApplicationEvent>((data, token) =>
{
    Console.WriteLine($"SUBSCRIPTION - {data.GetType().Name}: {JsonSerializer.Serialize(data)}");
    return Task.CompletedTask;
});
#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.

Exceptions (if any)

No response

.NET Version info

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions