dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.9k stars 469 forks source link

Support injecting `ExtraInterfaces` on generated project metadata during build #5683

Open captainsafia opened 2 months ago

captainsafia commented 2 months ago

For some scenarios, specifically Azure Functions, we want to implement Functions-specific behavior in Aspire APIs like Azure Functions. We currently achieve this by defining a custom AzureFunctionsResource resource type that is a wrapper around the default ProjectResource type. This pattern allows us to model specific behavior to target AzureFunctionsResource. However, it requires that users call the AddAzureFunctionsProject extension method in order to be able to invoke Functions-specific code.

An additional approach is to support attaching additional metadata into pre-existing ProjectResources and support targeting our Functions-specific methods onto that interface:

public class AzureFunctionsTest_Functions : global::Aspire.Hosting.IProjectMetadata, IFunctionsMetadata

In order to support this scenario, we need to be able to customize the interfaces that are applied to the AzureFunctionsTest_Functions type via MSBuild and the cogeneration step. To achieve this, we need to support an @(ExtraInterfaces) property that hosting packages can populate with additional interfaces that need to be applied on projects they target.

The flow of this would look as follows:

// package: Aspire.Hosting

namespace Aspire.Hosting;

public interface IFunctionsProjectMetadata { }
captainsafia commented 1 month ago

I'm gonna move this out of 9.0 since I don't think we'll be able to deliver something before 9.0 for this.

I think this is a good candidate for post-9.0 work though.

We'll have to reason through how some of the changes we applied for Functions, I'm thinking specifically about the endpoint/port related changes for publishing, will mesh with fully modeling Functions as projects.