# DockerfileFactoryContext Properties

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [DockerfileFactoryContext](/reference/api/csharp/aspire.hosting/dockerfilefactorycontext.md)
- Kind: `Properties`
- Members: `3`

Provides context for Dockerfile factory functions.

## CancellationToken

- Name: `CancellationToken`
- Modifiers: `get; init`
- Returns: `CancellationToken`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

Gets the cancellation token for the operation.

```csharp
public CancellationToken CancellationToken { get; init; }
```

## Resource

- Name: `Resource`
- Modifiers: `get; init`
- Returns: [IResource](/reference/api/csharp/aspire.hosting/iresource.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

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";
```

```csharp
public IResource Resource { get; init; }
```

## Services

- Name: `Services`
- Modifiers: `get; init`
- Returns: `IServiceProvider`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/bd20f904cde09ecb9c9ae5116a6f13614bf2d7c2/src/Aspire.Hosting/ApplicationModel/DockerfileFactoryContext.cs)

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>();
```

```csharp
public IServiceProvider Services { get; init; }
```
