# IGrainFactory Methods

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

## CreateObjectReference(IGrainObserver) {#createobjectreference-1-orleans-igrainobserver-d8b8f98a}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/createobjectreference-1-orleans-igrainobserver-d8b8f98a/)

```csharp
public abstract TGrainObserverInterface CreateObjectReference<TGrainObserverInterface>(IGrainObserver obj)
```

Creates a reference to the provided `obj`.

### Parameters

- `obj` (`IGrainObserver`): The object to create a reference to.

### Returns

The reference to `obj`.

## DeleteObjectReference(IGrainObserver) {#deleteobjectreference-1-orleans-igrainobserver-f5167deb}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/deleteobjectreference-1-orleans-igrainobserver-f5167deb/)

```csharp
public abstract void DeleteObjectReference<TGrainObserverInterface>(IGrainObserver obj)
```

Deletes the provided object reference.

### Parameters

- `obj` (`IGrainObserver`): The reference being deleted.

### Returns

A `System.Threading.Tasks.Task` representing the work performed.

## GetGrain(GrainId) {#getgrain-orleans-runtime-grainid-9362e357}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-orleans-runtime-grainid-9362e357/)

```csharp
public abstract IAddressable GetGrain(GrainId grainId)
```

Returns an untyped reference for the provided grain id.

### Parameters

- `grainId` (`GrainId`): The grain id.

### Returns

An untyped reference for the provided grain id.

## GetGrain(GrainId, GrainInterfaceType) {#getgrain-orleans-runtime-grainid-orleans-runtime-graininterfacetype-3ac1151c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-orleans-runtime-grainid-orleans-runtime-graininterfacetype-3ac1151c/)

```csharp
public abstract IAddressable GetGrain(GrainId grainId, GrainInterfaceType interfaceType)
```

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

### Parameters

- `grainId` (`GrainId`): The grain id.
- `interfaceType` (`GrainInterfaceType`): The interface type which the returned grain reference must implement.

### Returns

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

## GetGrain(Type, IdSpan) {#getgrain-system-type-orleans-runtime-idspan-3d360837}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-orleans-runtime-idspan-3d360837/)

```csharp
public abstract IAddressable GetGrain(Type interfaceType, IdSpan grainKey)
```

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

### Parameters

- `interfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainKey` (`IdSpan`): The primary key of the grain

### Returns

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

## GetGrain(Type, IdSpan, string) {#getgrain-system-type-orleans-runtime-idspan-string-c6de0a6c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-orleans-runtime-idspan-string-c6de0a6c/)

```csharp
public abstract IAddressable GetGrain(Type interfaceType, IdSpan grainKey, string grainClassNamePrefix)
```

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

### Parameters

- `interfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainKey` (`IdSpan`): The primary key of the grain
- `grainClassNamePrefix` (`string`): A 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.

## GetGrain(Type, Guid) {#getgrain-system-type-system-guid-bf7da003}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-system-guid-bf7da003/)

```csharp
public abstract IGrain GetGrain(Type grainInterfaceType, Guid grainPrimaryKey)
```

Returns a reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

### Parameters

- `grainInterfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainPrimaryKey` (`Guid`): The primary key of the grain

### Returns

A reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

## GetGrain(Type, Guid, string) {#getgrain-system-type-system-guid-string-9a9599e2}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-system-guid-string-9a9599e2/)

```csharp
public abstract IGrain GetGrain(Type grainInterfaceType, Guid grainPrimaryKey, string keyExtension)
```

Returns a reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

### Parameters

- `grainInterfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainPrimaryKey` (`Guid`): The primary key of the grain
- `keyExtension` (`string`): The grain key extension component.

### Returns

A reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

## GetGrain(Type, long) {#getgrain-system-type-long-50faca92}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-long-50faca92/)

```csharp
public abstract IGrain GetGrain(Type grainInterfaceType, long grainPrimaryKey)
```

Returns a reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

### Parameters

- `grainInterfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainPrimaryKey` (`long`): The primary key of the grain

### Returns

A reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

## GetGrain(Type, long, string) {#getgrain-system-type-long-string-716c1515}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-long-string-716c1515/)

```csharp
public abstract IGrain GetGrain(Type grainInterfaceType, long grainPrimaryKey, string keyExtension)
```

Returns a reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

### Parameters

- `grainInterfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainPrimaryKey` (`long`): The primary key of the grain
- `keyExtension` (`string`): The grain key extension component.

### Returns

A reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

## GetGrain(Type, string) {#getgrain-system-type-string-32fe07b3}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-system-type-string-32fe07b3/)

```csharp
public abstract IGrain GetGrain(Type grainInterfaceType, string grainPrimaryKey)
```

Returns a reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

### Parameters

- `grainInterfaceType` (`Type`): The grain interface type which the returned grain reference must implement.
- `grainPrimaryKey` (`string`): The primary key of the grain

### Returns

A reference to the grain which is the primary implementation of the provided interface type and has the provided primary key.

## GetGrain(GrainId) {#getgrain-1-orleans-runtime-grainid-17009c56}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-1-orleans-runtime-grainid-17009c56/)

```csharp
public abstract TGrainInterface GetGrain<TGrainInterface>(GrainId grainId)
```

Returns a reference to the specified grain which implements the specified interface.

### Parameters

- `grainId` (`GrainId`): The grain id.

### Returns

A reference to the specified grain which implements the specified interface.

## GetGrain(Guid, string, string?) {#getgrain-1-system-guid-string-string-nullable-16e2e263}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-1-system-guid-string-string-nullable-16e2e263/)

```csharp
public abstract TGrainInterface GetGrain<TGrainInterface>(Guid primaryKey, string keyExtension, string? grainClassNamePrefix = null)
```

Gets a reference to a grain.

### Parameters

- `primaryKey` (`Guid`): The primary key of the grain.
- `keyExtension` (`string`): The key extension of the grain.
- `grainClassNamePrefix` (`string?`): An optional class name prefix used to find the runtime type of the grain.

### Returns

A reference to the specified grain.

## GetGrain(Guid, string?) {#getgrain-1-system-guid-string-nullable-f7a20fc6}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-1-system-guid-string-nullable-f7a20fc6/)

```csharp
public abstract TGrainInterface GetGrain<TGrainInterface>(Guid primaryKey, string? grainClassNamePrefix = null)
```

Gets a reference to a grain.

### Parameters

- `primaryKey` (`Guid`): 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 to the specified grain.

## GetGrain(long, string, string?) {#getgrain-1-long-string-string-nullable-6003727c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-1-long-string-string-nullable-6003727c/)

```csharp
public abstract TGrainInterface GetGrain<TGrainInterface>(long primaryKey, string keyExtension, string? grainClassNamePrefix = null)
```

Gets a reference to a grain.

### Parameters

- `primaryKey` (`long`): The primary key of the grain.
- `keyExtension` (`string`): The key extension of the grain.
- `grainClassNamePrefix` (`string?`): An optional class name prefix used to find the runtime type of the grain.

### Returns

A reference to the specified grain.

## GetGrain(long, string?) {#getgrain-1-long-string-nullable-b3777177}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-1-long-string-nullable-b3777177/)

```csharp
public abstract TGrainInterface GetGrain<TGrainInterface>(long primaryKey, string? grainClassNamePrefix = null)
```

Gets a reference to a grain.

### Parameters

- `primaryKey` (`long`): 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 to the specified grain.

## GetGrain(string, string?) {#getgrain-1-string-string-nullable-6f4860ca}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.core.abstractions/orleans.igrainfactory/methods/getgrain-1-string-string-nullable-6f4860ca/)

```csharp
public abstract TGrainInterface GetGrain<TGrainInterface>(string primaryKey, string? grainClassNamePrefix = null)
```

Gets a reference to a grain.

### Parameters

- `primaryKey` (`string`): 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 to the specified grain.
