# DockerfileFactoryContext

- Kind: `class`
- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Version: `13.3.0`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net8.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

Provides context for Dockerfile factory functions.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public sealed class DockerfileFactoryContext
{
    // ...
}
```

## Constructors

- [DockerfileFactoryContext](/reference/api/csharp/aspire.hosting/dockerfilefactorycontext/constructors.md#constructor)

## Properties

- [CancellationToken](/reference/api/csharp/aspire.hosting/dockerfilefactorycontext/properties.md#cancellationtoken) : `CancellationToken` `get; init` -- Gets the cancellation token for the operation.
- [Resource](/reference/api/csharp/aspire.hosting/dockerfilefactorycontext/properties.md#resource) : [IResource](/reference/api/csharp/aspire.hosting/iresource.md) `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. ```csharp var containerAnnotation = context.Resource.Annotations.OfType<ContainerImageAnnotation>().FirstOrDefault(); var baseImage = containerAnnotation?.Image ?? "alpine:latest"; ```
- [Services](/reference/api/csharp/aspire.hosting/dockerfilefactorycontext/properties.md#services) : `IServiceProvider` `get; init` -- 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. ```csharp var logger = context.Services.GetRequiredService<ILogger>(); ```
