Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Aspire.Hosting/DistributedApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ private DistributedApplicationExecutionContextOptions BuildExecutionContextOptio
{
DistributedApplicationOperation.Run => new DistributedApplicationExecutionContextOptions(operation),
DistributedApplicationOperation.Inspect => new DistributedApplicationExecutionContextOptions(operation),
_ => new DistributedApplicationExecutionContextOptions(operation, _innerBuilder.Configuration["Publishing:Publisher"])
DistributedApplicationOperation.Publish => new DistributedApplicationExecutionContextOptions(operation, _innerBuilder.Configuration["Publishing:Publisher"] ?? "manifest"),
_ => throw new DistributedApplicationException("Invalid operation specified. Valid operations are 'publish', 'inspect', or 'run'.")
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DistributedApplicationExecutionContext(DistributedApplicationOperation op
/// <summary>
/// The name of the publisher that is being used if <see cref="Operation"/> is set to <see cref="DistributedApplicationOperation.Publish"/>.
/// </summary>
public string? PublisherName { get; set; }
public string PublisherName { get; set; }

private readonly DistributedApplicationExecutionContextOptions? _options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ public class DistributedApplicationExecutionContextOptions
/// Constructs a <see cref="DistributedApplicationExecutionContextOptions" />.
/// </summary>
/// <param name="operation">Indicates whether the AppHost is running in Publish mode or Run mode.</param>
public DistributedApplicationExecutionContextOptions(DistributedApplicationOperation operation) : this(operation, null)
public DistributedApplicationExecutionContextOptions(DistributedApplicationOperation operation)
{
this.Operation = operation;
}

/// <summary>
/// Constructs a <see cref="DistributedApplicationExecutionContextOptions" />.
/// </summary>
/// <param name="operation">Indicates whether the AppHost is running in Publish mode or Run mode.</param>
/// <param name="publisherName">The publisher name if in Publish mode.</param>
public DistributedApplicationExecutionContextOptions(DistributedApplicationOperation operation, string? publisherName = null)
public DistributedApplicationExecutionContextOptions(DistributedApplicationOperation operation, string publisherName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why couldn't this stay as

public DistributedApplicationExecutionContextOptions(DistributedApplicationOperation operation, string? publisherName)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a call with @mitchdenny and if you want to no set a valid publishname you can use the other ctor.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, that kind of API pattern makes using the API harder to use. It maybe doesn't matter much for this API, but in general, the pattern isn't great.

void Foo() { ... }
void Foo(string v) { ... }

// consume:

string? someV = GetSomeV();

if (someV is null)
{
    Foo();
}
else
{
    Foo(someV);
}

vs.

void Foo() { ... }
void Foo(string? v) { ... }

// consume:

string? someV = GetSomeV();
Foo(someV);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. In that case the usage is based on the first argument, operation, and if you are creating a Publish operation you have to set a non-null publisherName. So maybe the API could have been more specific about it, even maybe preventing from setting a publisherName if you create another type (Run or Inspect). For instance ctor(string publisherName) would be more adapted, it would infer the Publish operation. Or maybe these should be sub-classes.

{
this.Operation = operation;
this.PublisherName = publisherName;
Expand All @@ -38,7 +39,7 @@ public DistributedApplicationExecutionContextOptions(DistributedApplicationOpera
public DistributedApplicationOperation Operation { get; }

/// <summary>
/// The name of the publisher if running in pbublish mode.
/// The name of the publisher if running in publish mode.
/// </summary>
public string? PublisherName { get; }
}
Loading