Skip to content
DocsTry Aspire
DocsTry

DockerfileFactoryContext Properties

ClassProperties3 members
Provides context for Dockerfile factory functions.
CancellationTokenSection titled CancellationTokenCancellationToken
Gets the cancellation token for the operation.
public CancellationToken CancellationToken { get; 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";
public IResource Resource { get; init; }
ServicesSection titled ServicesIServiceProvider
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>();
public IServiceProvider Services { get; init; }