Overload AddProject in ProjectResourceBuilderExtensions for providing ProjectResource
- 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
Assessment
This issue has not been assessed yet.