# GrainFactoryExtensions Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainfactoryextensions/)

## GetGrain(IGrainFactory, IdSpan) {#getgrain-1-this-orleans-igrainfactory-orleans-runtime-idspan-fdc4ff69}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainfactoryextensions/methods/getgrain-1-this-orleans-igrainfactory-orleans-runtime-idspan-fdc4ff69/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainFactory.cs#L36-L37)

```csharp
public static TGrainInterface GetGrain<TGrainInterface>(this IGrainFactory grainFactory, IdSpan grainPrimaryKey)
```

Returns a reference for the provided grain id which implements the specified interface type.

### Parameters

- `grainFactory` (`IGrainFactory`): The grain factory.
- `grainPrimaryKey` (`IdSpan`): The primary key of the grain

### Returns

A reference for the provided grain id which implements the specified interface type.

## GetGrain(IGrainFactory, IdSpan, string) {#getgrain-1-this-orleans-igrainfactory-orleans-runtime-idspan-string-9233a20e}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.grainfactoryextensions/methods/getgrain-1-this-orleans-igrainfactory-orleans-runtime-idspan-string-9233a20e/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Orleans.Core.Abstractions/Core/IGrainFactory.cs#L21-L22)

```csharp
public static TGrainInterface GetGrain<TGrainInterface>(this IGrainFactory grainFactory, IdSpan grainPrimaryKey, string grainClassNamePrefix)
```

Returns a reference for the provided grain id which implements the specified interface type.

### Parameters

- `grainFactory` (`IGrainFactory`): The grain factory.
- `grainPrimaryKey` (`IdSpan`): The primary key of the grain
- `grainClassNamePrefix` (`string`): An optional class name prefix used to find the runtime type of the grain.

### Returns

A reference for the provided grain id which implements the specified interface type.
