-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Mixing attributes #107
Comments
+1 |
I like the straightforward approach. Maybe the naming for some categories will be a different. |
@gabikliot sure, it was just an example |
Should we catch such violations at compile/codegen time, just like we do for grain interface rules? |
@sergeybykov hmmm, but isn't codegen only operates on interface project? And those attributes target grain class implementations ... |
Codegen runs for grain implementations too, to generate state classes from state interfaces. |
To clarify, I meant to say that in addition to structuring attributes into categories and having compiler enforce AllowMultiple=false, which I think is a great suggestion, we can also catch any violations that pass that filter at codegen time. |
Another +1 for grouping attributes. On Tue, 10 Feb 2015 22:10 Sergey Bykov notifications@github.com wrote:
|
@sergeybykov ah, sorry, forgot about that. I don't use built-in persistence :) Ye, it would be great, since grouping into category attributes with backed choice enums is not enough to catch invalid combinations across categories, such as StatelessWorker + Placement, or Reentrant + AlwaysInterleave |
From my PoC, I've think that best way to group attributes is by having a configuration attribute for each type of activation. That will elegantly restrict what could be configured for each type of activation: public enum Placement
{
Auto,
PreferLocal,
DistributeEvenly
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class GrainAttribute : Attribute
{
public readonly Placement Placement;
public GrainAttribute(Placement placement = Placement.Auto)
{
Placement = placement;
}
}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public class StatelessWorkerAttribute : Attribute
{
// no additional configuration options at the moment
} That only leaves us with mixing |
There are a number of attribute combinations which doesn't make sense to mix together. For example: mixing StatelessWorker with any of Placement attributes doesn't make sense, but it looks like currently it is allowed to combine them within same class declaration.
I'm not sure what will happen in this case and I guess that handling code is smart enough to just ignore placement attributes if used along with StatelessWorker. Nevertheless, I found it to be confusing and I think it might be better to fail with exception to prevent users polluting grain declarations with useless combinations of attributes, which will confuse all future readers. Also, such validation should prevent users from cargo-culting Orleans.
Other invalid combinations:
Another, possible and probably more intuitive approach will be, is to group all choices under respective category attributes (and use AllowMultiple=false), to make alternation explcit. Something like:
What do you think?
The text was updated successfully, but these errors were encountered: