AzureSearchExtensions Methods
ClassMethods2 members
Provides extension methods for adding the Azure AI Search resources to the application model.
AddAzureSearch(IDistributedApplicationBuilder, string)Section titled AddAzureSearch(IDistributedApplicationBuilder, string)extensionIResourceBuilder<AzureSearchResource> Adds an Azure AI Search service resource to the application model.
public static class AzureSearchExtensions{ public static IResourceBuilder<AzureSearchResource> AddAzureSearch( this IDistributedApplicationBuilder builder, string name) { // ... }}Parameters
builderIDistributedApplicationBuilderThe builder for the distributed application.namestringThe name of the Azure AI Search resource.Returns
IResourceBuilder<AzureSearchResource>A reference to the ApplicationModel.IResourceBuilder`1.Remarks
By default references to the Azure AI Search service resource will be assigned the following roles: -
SearchBuiltInRole.SearchIndexDataContributor - SearchBuiltInRole.SearchServiceContributor These can be replaced by calling AzureSearchExtensions.WithRoleAssignments. WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureSearchResource>, SearchBuiltInRole[])Section titled WithRoleAssignments(IResourceBuilder<T>, IResourceBuilder<AzureSearchResource>, SearchBuiltInRole[])extensionIResourceBuilder<T> Assigns the specified roles to the given resource, granting it the necessary permissions on the target Azure AI Search service resource. This replaces the default role assignments for the resource.
public static class AzureSearchExtensions{ public static IResourceBuilder<T> WithRoleAssignments<T>( this IResourceBuilder<T> builder, IResourceBuilder<AzureSearchResource> target, params SearchBuiltInRole[] roles) { // ... }}Parameters
builderIResourceBuilder<T>The resource to which the specified roles will be assigned.targetIResourceBuilder<AzureSearchResource>The target Azure AI Search service resource.rolesSearchBuiltInRole[]The built-in AI Search roles to be assigned.Returns
IResourceBuilder<T>The updated ApplicationModel.IResourceBuilder`1 with the applied role assignments.Remarks
Assigns the SearchIndexDataReader role to the 'Projects.Api' project.
var builder = DistributedApplication.CreateBuilder(args);
var search = builder.AddAzureSearch("search");
var api = builder.AddProject<Projects.Api>("api") .WithRoleAssignments(search, SearchBuiltInRole.SearchIndexDataReader) .WithReference(search);