DockerfileFactoryContext
Class sealed net10.0
Provides context for Dockerfile factory functions.
namespace Aspire.Hosting.ApplicationModel;
public sealed class DockerfileFactoryContext{ // ...}Constructors1
Section titled ConstructorsProperties3
Section titled PropertiesCancellationTokenget; initCancellationToken Gets the cancellation token for the operation.
Resourceget; init Gets the resource for which the Dockerfile is being generated.
This allows factory functions to query resource annotations and properties to customize the generated Dockerfile.
var containerAnnotation = context .Resource .Annotations .OfType<ContainerImageAnnotation>( ).FirstOrDefault();var baseImage = containerAnnotation?.Image ?? "alpine:latest";Servicesget; initIServiceProvider Gets the
IServiceProvider for resolving dependencies required by Dockerfile factory functions. The service provider typically contains services such as IHostEnvironment, ILogger, and configuration objects relevant to the application model. Factory functions can use this provider to obtain required services for generating Dockerfiles.
var logger = context.Services.GetRequiredService<ILogger>();