Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grain state feature does not support state of generic Grain base type #400

Open
koenbeuk opened this issue Jun 22, 2023 · 1 comment
Open

Comments

@koenbeuk
Copy link
Contributor

Just got a chance to use this: #360

The grain state feature works fine when my grain is shaped as:

class MyGrain : Grain, IMyGrain { 
  readonly IPersistentState<ProfileState> state;
 
  public MyGrain([PersistentState("profile", "profileStore")] IPersistentState<ProfileState> state) { 
    _state = state;
  }
}

and

class MyGrain : Grain, IMyGrain {  
  public MyGrain([PersistentState("profile", "profileStore")] IPersistentState<ProfileState> state) { 
    State = state;
  }

  protected IPersistentState<ProfileState> State { get; }
}

But not when:

class MyGrain : Grain<ProfileState>, IMyGrain {  }

If I'm correct, the recommended practice from Orleans is to use the constructor approach however the generic base type approach is just convenient and while we wait for primary constructors to be implemented in C#, I think we should consider adding support for this.

@koenbeuk
Copy link
Contributor Author

At first glance, it seems that this could be implemented here: https://github.com/OrleansContrib/OrleansDashboard/blob/4b9dd9ed86038a0a6b254cc2ce5c8dfb6edbeb2b/OrleansDashboard/Implementation/Helpers/GrainStateHelper.cs#LL67C1-L67C1

Happy to issue a PR if there is an agreement that this is valuable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant