microsoft / microsoft/aspire

Overload AddProject in ProjectResourceBuilderExtensions for providing ProjectResource

Open
#3,481 4 comments 2 reactions 0 assignees View on GitHub
area-app-model
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

The class `ProjectResource` is extendable, but doing so removes the possibility of accessing `ProjectResourceBuilderExtensions.WithProjectDefaults`.

One reason for extending `ProjectResource` is to provide extension methods only applicable to a project of a specific type.

Would overload(s) that uses `ProjectResource` instead of `name` be in alignment?

```csharp
public static IResourceBuilder AddProject(this IDistributedApplicationBuilder builder, ProjectResource project) where TProject : IProjectMetadata, new()
{
return builder.AddResource(project)
.WithAnnotation(new TProject())
.WithProjectDefaults(excludeLaunchProfile: false, launchProfileName: null);
}
```

In the scenario above the responsibility is placed on the developer to cast `IResourceBuilder` to `IResourceBuilder`.

The alternative is to further extend with a second generic parameter for the return type.

```csharp
public static IResourceBuilder AddProject(this IDistributedApplicationBuilder builder, TResource project) where TProject : IProjectMetadata, new() where TResource : ProjectResource
{
return builder.AddResource(project)
.WithAnnotation(new TProject())
.WithProjectDefaults(excludeLaunchProfile: false, launchProfileName: null);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.