Skip to content
Docs Try Aspire

FoundryExtensions Methods

Class Methods 6 members
Provides extension methods for adding the Microsoft Foundry resources to the application model.
AddDeployment(IResourceBuilder<FoundryResource>, string, string, string, string) Section titled AddDeployment(IResourceBuilder<FoundryResource>, string, string, string, string) extension IResourceBuilder<FoundryDeploymentResource>
Adds and returns a Microsoft Foundry Deployment resource (e.g. an AI model) to the application model.
public static class FoundryExtensions
{
public static IResourceBuilder<FoundryDeploymentResource> AddDeployment(
this IResourceBuilder<FoundryResource> builder,
string name,
string modelName,
string modelVersion,
string format)
{
// ...
}
}
builder IResourceBuilder<FoundryResource> The Microsoft Foundry resource builder.
name string The name of the Microsoft Foundry Deployment resource.
modelName string The name of the model to deploy.
modelVersion string The version of the model to deploy.
format string The format of the model to deploy.
IResourceBuilder<FoundryDeploymentResource> A reference to the ApplicationModel.IResourceBuilder`1.
AddDeployment(IResourceBuilder<FoundryResource>, string, FoundryModel) Section titled AddDeployment(IResourceBuilder<FoundryResource>, string, FoundryModel) extension IResourceBuilder<FoundryDeploymentResource>
Adds and returns a Microsoft Foundry Deployment resource to the application model using a FoundryModel.
public static class FoundryExtensions
{
public static IResourceBuilder<FoundryDeploymentResource> AddDeployment(
this IResourceBuilder<FoundryResource> builder,
string name,
FoundryModel model)
{
// ...
}
}
builder IResourceBuilder<FoundryResource> The Microsoft Foundry resource builder.
name string The name of the Microsoft Foundry Deployment resource.
model FoundryModel The model descriptor, using the FoundryModel class like so:
aiFoundry.AddDeployment(name: "chat", model: FoundryModel.OpenAI.Gpt5Mini)
IResourceBuilder<FoundryDeploymentResource> A reference to the ApplicationModel.IResourceBuilder`1.
Create a deployment for the OpenAI GTP-5-mini model:
var builder = DistributedApplication.CreateBuilder(args);
var aiFoundry = builder.AddFoundry("aiFoundry");
var gpt5mini = aiFoundry.AddDeployment("chat", FoundryModel.OpenAI.Gpt5Mini);
AddFoundry(IDistributedApplicationBuilder, string) Section titled AddFoundry(IDistributedApplicationBuilder, string) extension IResourceBuilder<FoundryResource>
Adds a Microsoft Foundry resource to the application model.
public static class FoundryExtensions
{
public static IResourceBuilder<FoundryResource> AddFoundry(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
name string The name of the resource. This name will be used as the connection string name when referenced in a dependency.
IResourceBuilder<FoundryResource> A reference to the ApplicationModel.IResourceBuilder`1.
RunAsFoundryLocal(IResourceBuilder<FoundryResource>) Section titled RunAsFoundryLocal(IResourceBuilder<FoundryResource>) extension IResourceBuilder<FoundryResource>
Adds a Foundry Local resource to the distributed application builder.
public static class FoundryExtensions
{
public static IResourceBuilder<FoundryResource> RunAsFoundryLocal(
this IResourceBuilder<FoundryResource> builder)
{
// ...
}
}
builder IResourceBuilder<FoundryResource> The distributed application builder.
IResourceBuilder<FoundryResource> A resource builder for the Foundry Local resource.
WithProperties(IResourceBuilder<FoundryDeploymentResource>, Action<FoundryDeploymentResource>) Section titled WithProperties(IResourceBuilder<FoundryDeploymentResource>, Action<FoundryDeploymentResource>) extension IResourceBuilder<FoundryDeploymentResource>
Allows setting the properties of a Microsoft Foundry Deployment resource.
public static class FoundryExtensions
{
public static IResourceBuilder<FoundryDeploymentResource> WithProperties(
this IResourceBuilder<FoundryDeploymentResource> builder,
Action<FoundryDeploymentResource> configure)
{
// ...
}
}
builder IResourceBuilder<FoundryDeploymentResource> The Microsoft Foundry Deployment resource builder.
configure Action<FoundryDeploymentResource> A method that can be used for customizing the FoundryDeploymentResource.
IResourceBuilder<FoundryDeploymentResource> A reference to the ApplicationModel.IResourceBuilder`1.
WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<FoundryResource>, CognitiveServicesBuiltInRole[]) Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<FoundryResource>, CognitiveServicesBuiltInRole[]) extension IResourceBuilder<T>
Assigns the specified roles to the given resource, granting it the necessary permissions on the target Microsoft Foundry resource. This replaces the default role assignments for the resource.
public static class FoundryExtensions
{
public static IResourceBuilder<T> WithRoleAssignments<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<FoundryResource> target,
params CognitiveServicesBuiltInRole[] roles)
{
// ...
}
}
builder IResourceBuilder<T> The resource to which the specified roles will be assigned.
target IResourceBuilder<FoundryResource> The target Microsoft Foundry resource.
roles CognitiveServicesBuiltInRole[] The built-in Cognitive Services roles to be assigned.
IResourceBuilder<T> The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments.
Assigns the CognitiveServicesOpenAIContributor role to the 'Projects.Api' project.
var builder = DistributedApplication.CreateBuilder(args);
var aiFoundry = builder.AddFoundry("aiFoundry");
var api = builder.AddProject<Projects.Api>("api")
.WithRoleAssignments(
aiFoundry,
CognitiveServicesBuiltInRole.CognitiveServicesOpenAIContributor)
.WithReference(aiFoundry);