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

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

[Source](https://github.com/dotnet/orleans/blob/6a0e937f544c35ffcf11b37e4c2b7de5a1580a03/src/Orleans.Durable/Journaling/JournalingHostingExtensions.cs#L128-L144)

```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.
