-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathPapercutSmtpHostingExtension.cs
More file actions
42 lines (38 loc) · 2.02 KB
/
Copy pathPapercutSmtpHostingExtension.cs
File metadata and controls
42 lines (38 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Aspire.Hosting.ApplicationModel;
using CommunityToolkit.Aspire.Hosting.PapercutSmtp;
namespace Aspire.Hosting;
/// <summary>
/// Provides extension methods for adding DataApiBuilder api to an <see cref="IDistributedApplicationBuilder"/>.
/// </summary>
public static class PapercutSmtpHostingExtension
{
/// <summary>
/// Adds Papercut SMTP to the application model.
/// </summary>
/// <param name="builder">The <see cref="IDistributedApplicationBuilder"/> to add the resource to.</param>
/// <param name="name">The name of the resource.</param>
/// <param name="httpPort">The HTTP portnumber for the web-console to the Papercut SMTP container.</param>
/// <param name="smtpPort">The SMTP portnumber for the Papercut SMTP Conteainer</param>
/// <returns>A reference to the <see cref="IResourceBuilder{T}"/>.</returns>
public static IResourceBuilder<PapercutSmtpContainerResource> AddPapercutSmtp(this IDistributedApplicationBuilder builder,
[ResourceName] string name,
int? httpPort = null,
int? smtpPort = null)
{
ArgumentNullException.ThrowIfNull("Service name must be specified.", nameof(name));
PapercutSmtpContainerResource resource = new(name);
IResourceBuilder<PapercutSmtpContainerResource> rb = builder.AddResource(resource)
.WithImage(PapercutSmtpContainerImageTags.Image)
.WithImageTag(PapercutSmtpContainerImageTags.Tag)
.WithImageRegistry(PapercutSmtpContainerImageTags.Registry)
.WithEndpoint(targetPort: PapercutSmtpContainerResource.SmtpEndpointPort,
port: smtpPort,
name: PapercutSmtpContainerResource.SmtpEndpointName,
scheme: "smtp")
.WithHttpEndpoint(targetPort: PapercutSmtpContainerResource.HttpEndpointPort,
port: httpPort,
name: PapercutSmtpContainerResource.HttpEndpointName)
.WithHttpHealthCheck("/health", httpPort, PapercutSmtpContainerResource.HttpEndpointName);
return rb;
}
}