# JournalingHostingExtensions.AddStateMachine(IServiceCollection, Func&lt;IServiceProvider, string, TImplementation&gt;)

[Type overview](/orleans/docs/api/csharp/microsoft.orleans.journaling/orleans.journaling.journalinghostingextensions/) | [Methods](/orleans/docs/api/csharp/microsoft.orleans.journaling/orleans.journaling.journalinghostingextensions/methods/)

[Source](https://github.com/dotnet/orleans/blob/8bc9fd244427351ad24ccc039a9e7642a42c1cc4/src/Orleans.Journaling/JournalingHostingExtensions.cs#L101-L117)

```csharp
public static IServiceCollection AddStateMachine<TState, TImplementation>(this IServiceCollection services, Func<IServiceProvider, string, TImplementation> factory)
```

Registers a factory for a custom durable state contract.

### Parameters

- `services` (`IServiceCollection`): The service collection.
- `factory` (`Func<IServiceProvider, string, TImplementation>`): Creates a state component using its activation's service scope and stable state name.

### Returns

The service collection.
