# CosmosGrainStorage Methods

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/)

## ClearStateAsync(string, GrainId, IGrainState&lt;T&gt;) {#clearstateasync-1-string-orleans-runtime-grainid-orleans-igrainstate-t-46dbc51d}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/methods/clearstateasync-1-string-orleans-runtime-grainid-orleans-igrainstate-t-46dbc51d/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs#L171-L253)

```csharp
public Task ClearStateAsync<T>(string grainType, GrainId grainId, IGrainState<T> grainState)
```

Delete / Clear data function for this storage instance.

### Parameters

- `grainType` (`string`): Name of the state for this grain
- `grainId` (`GrainId`): Grain ID
- `grainState` (`IGrainState<T>`): Copy of last-known state data object for this grain.

### Returns

Completion promise for the Delete operation on the specified grain.

## Participate(ISiloLifecycle) {#participate-orleans-runtime-isilolifecycle-787c1ac1}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/methods/participate-orleans-runtime-isilolifecycle-787c1ac1/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs#L257-L258)

```csharp
public void Participate(ISiloLifecycle lifecycle)
```

Adds the provided observer as a participant in the lifecycle.

### Parameters

- `lifecycle` (`ISiloLifecycle`): The observer.

## ReadStateAsync(string, GrainId, IGrainState&lt;T&gt;) {#readstateasync-1-string-orleans-runtime-grainid-orleans-igrainstate-t-bd972d7c}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/methods/readstateasync-1-string-orleans-runtime-grainid-orleans-igrainstate-t-bd972d7c/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs#L50-L97)

```csharp
public Task ReadStateAsync<T>(string grainType, GrainId grainId, IGrainState<T> grainState)
```

Read data function for this storage instance.

### Parameters

- `grainType` (`string`): Name of the state for this grain
- `grainId` (`GrainId`): Grain ID
- `grainState` (`IGrainState<T>`): State data object to be populated for this grain.

### Returns

Completion promise for the Read operation on the specified grain.

## WriteStateAsync(string, GrainId, IGrainState&lt;T&gt;) {#writestateasync-1-string-orleans-runtime-grainid-orleans-igrainstate-t-ce2dbd4f}

[Dedicated page](/orleans/docs/api/csharp/microsoft.orleans.persistence.cosmos/orleans.persistence.cosmos.cosmosgrainstorage/methods/writestateasync-1-string-orleans-runtime-grainid-orleans-igrainstate-t-ce2dbd4f/)

[Source](https://github.com/dotnet/orleans/blob/e4e752cedecc2976811db49802c7a999b1f1c704/src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs#L101-L167)

```csharp
public Task WriteStateAsync<T>(string grainType, GrainId grainId, IGrainState<T> grainState)
```

Write data function for this storage instance.

### Parameters

- `grainType` (`string`): Name of the state for this grain
- `grainId` (`GrainId`): Grain ID
- `grainState` (`IGrainState<T>`): State data object to be written for this grain.

### Returns

Completion promise for the Write operation on the specified grain.
