FoundryExtensions Methods
ClassMethods6 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)extensionIResourceBuilder<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) { // ... }}Parameters
builderIResourceBuilder<FoundryResource>The Microsoft Foundry resource builder.namestringThe name of the Microsoft Foundry Deployment resource.modelNamestringThe name of the model to deploy.modelVersionstringThe version of the model to deploy.formatstringThe format of the model to deploy.Returns
IResourceBuilder<FoundryDeploymentResource>A reference to the ApplicationModel.IResourceBuilder`1.AddDeployment(IResourceBuilder<FoundryResource>, string, FoundryModel)Section titled AddDeployment(IResourceBuilder<FoundryResource>, string, FoundryModel)extensionIResourceBuilder<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) { // ... }}Parameters
builderIResourceBuilder<FoundryResource>The Microsoft Foundry resource builder.namestringThe name of the Microsoft Foundry Deployment resource.modelFoundryModelThe model descriptor, using the FoundryModel class like so: aiFoundry.AddDeployment(name: "chat", model: FoundryModel.OpenAI.Gpt5Mini)Returns
IResourceBuilder<FoundryDeploymentResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
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)extensionIResourceBuilder<FoundryResource> Adds a Microsoft Foundry resource to the application model.
public static class FoundryExtensions{ public static IResourceBuilder<FoundryResource> AddFoundry( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.Returns
IResourceBuilder<FoundryResource>A reference to the ApplicationModel.IResourceBuilder`1.RunAsFoundryLocal(IResourceBuilder<FoundryResource>)Section titled RunAsFoundryLocal(IResourceBuilder<FoundryResource>)extensionIResourceBuilder<FoundryResource> Adds a Foundry Local resource to the distributed application builder.
public static class FoundryExtensions{ public static IResourceBuilder<FoundryResource> RunAsFoundryLocal( this IResourceBuilder<FoundryResource> builder) { // ... }}Parameters
builderIResourceBuilder<FoundryResource>The distributed application builder.Returns
IResourceBuilder<FoundryResource>A resource builder for the Foundry Local resource.WithProperties(IResourceBuilder<FoundryDeploymentResource>, Action<FoundryDeploymentResource>)Section titled WithProperties(IResourceBuilder<FoundryDeploymentResource>, Action<FoundryDeploymentResource>)extensionIResourceBuilder<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) { // ... }}Parameters
builderIResourceBuilder<FoundryDeploymentResource>The Microsoft Foundry Deployment resource builder.configureAction<FoundryDeploymentResource>A method that can be used for customizing the FoundryDeploymentResource.Returns
IResourceBuilder<FoundryDeploymentResource>A reference to the ApplicationModel.IResourceBuilder`1.WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<FoundryResource>, CognitiveServicesBuiltInRole[])Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<FoundryResource>, CognitiveServicesBuiltInRole[])extensionIResourceBuilder<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) { // ... }}Parameters
builderIResourceBuilder<T>The resource to which the specified roles will be assigned.targetIResourceBuilder<FoundryResource>The target Microsoft Foundry resource.rolesCognitiveServicesBuiltInRole[]The built-in Cognitive Services roles to be assigned.Returns
IResourceBuilder<T>The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments.Remarks
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);