dotnet / orleans

Cloud Native application framework for .NET
https://docs.microsoft.com/dotnet/orleans
MIT License
10.11k stars 2.04k forks source link

Custom Storage Provider: PubSubGrainState is internal so cannot be stored #9222

Open nkosi23 opened 1 week ago

nkosi23 commented 1 week ago

I am facing a challenge that I struggle to overcome.

I have implemented a custom storage provider, using an underlying data store that requires all documents being saved to have an Id property.

Since I use external libraries also using Orleans to persist state, I have added logic so that if the State type has an id field it is stored as is, otherwise, the state is wrapped in a generic wrapper type looking like the below:

type GrainStateWrapper<'T> = { Id: string; State: 'T }

Apparently, internally Orleans uses the PubSubGrainState as part of the streaming feature. Since this type does not have an Id property I need to wrap it, however I am getting a runtime issue when persisting the wrapper because the type is inaccessible as it is indeed marked as internal.

This also creates issues because the storage library I am using relies on a fluent API to discover and configure the types being persisted, but once again since the type is internal I cannot do that. I do not understand why a type needing to be persisted would be marked as internal.

Anyway, I wonder what my options are, as it doesn't look like I can easily swap the PubSubGrainState for another type.

Any idea would be greatly appreciated!

Thanks

nkosi23 commented 1 week ago

I have worked around this issue by using IGrainStorageSerializer.Serialize(state) to serialize this state as a base64 string.