Share via


EmbeddingGeneratorExtensions.GetRequiredService Method

Definition

Overloads

GetRequiredService(IEmbeddingGenerator, Type, Object)

Asks the IEmbeddingGenerator<TInput,TEmbedding> for an object of the specified type serviceType and throws an exception if one isn't available.

GetRequiredService<TService>(IEmbeddingGenerator, Object)

Asks the IEmbeddingGenerator<TInput,TEmbedding> for an object of type TService and throws an exception if one isn't available.

GetRequiredService(IEmbeddingGenerator, Type, Object)

Asks the IEmbeddingGenerator<TInput,TEmbedding> for an object of the specified type serviceType and throws an exception if one isn't available.

public static object GetRequiredService(this Microsoft.Extensions.AI.IEmbeddingGenerator generator, Type serviceType, object? serviceKey = default);
static member GetRequiredService : Microsoft.Extensions.AI.IEmbeddingGenerator * Type * obj -> obj
<Extension()>
Public Function GetRequiredService (generator As IEmbeddingGenerator, serviceType As Type, Optional serviceKey As Object = Nothing) As Object

Parameters

generator
IEmbeddingGenerator

The generator.

serviceType
Type

The type of object being requested.

serviceKey
Object

An optional key that can be used to help identify the target service.

Returns

The found object.

Exceptions

serviceType is null.

No service of the requested type for the specified key is available.

Remarks

The purpose of this method is to allow for the retrieval of services that are required to be provided by the IEmbeddingGenerator<TInput,TEmbedding>, including itself or any services it might be wrapping.

Applies to

GetRequiredService<TService>(IEmbeddingGenerator, Object)

Asks the IEmbeddingGenerator<TInput,TEmbedding> for an object of type TService and throws an exception if one isn't available.

public static TService GetRequiredService<TService>(this Microsoft.Extensions.AI.IEmbeddingGenerator generator, object? serviceKey = default);
static member GetRequiredService : Microsoft.Extensions.AI.IEmbeddingGenerator * obj -> 'Service
<Extension()>
Public Function GetRequiredService(Of TService) (generator As IEmbeddingGenerator, Optional serviceKey As Object = Nothing) As TService

Type Parameters

TService

The type of the object to be retrieved.

Parameters

generator
IEmbeddingGenerator

The generator.

serviceKey
Object

An optional key that can be used to help identify the target service.

Returns

TService

The found object.

Exceptions

generator is null.

No service of the requested type for the specified key is available.

Remarks

The purpose of this method is to allow for the retrieval of strongly typed services that are required to be provided by the IEmbeddingGenerator<TInput,TEmbedding>, including itself or any services it might be wrapping.

Applies to