-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Update visibility of component parameters #8825
Comments
I am not sure if this is a valid scenario, but moving to virtual protected/virtual public parameters might make component inheritance easier. I.e. one could make a specialized version of the NavLink component by inheriting from LavLink instead of wrapping it. |
Right you are. We have examples of this in the framework like |
Isn't there a guideline that we should consider using the "Composition over inheritance strategy" when using components? I think it's also used in React etc. |
Overall, very much agreed. C# doesn't have a modifier that really matches the scenario perfectly.
Sounds like the best option if such an analyzer is feasible. I don't know the perf characteristics of analyzers in the IDE, but of course this means our analyzer has to inspect every property-set call in every method in every opened project while you're typing. If it scales to that then great. We could still allow developers to have
It's also generally assumed that unused public code is dead code that can be removed, given that AOT operates on applications not on libraries. So I don't expect changing the visibility is going to make anything better for us here. |
This kind of thing actually works really well. You can to inspect every property when running a full build. When you're editing, you get to look at the class being worked on. The analyzer infrastructure just does this for you, it's pretty neat. |
The only concern that I have here is that we have people different guidance than we have been - but I think it's worth changing what we're doing, and in that case we can't avoid telling people to change their code. IMO we would want to roll this out in preview 7 along with an analyzer that tells you to conform to our guidlelines. Then in preview 8 (or later) we remove supports for non-public properties. |
@rynowak I don't mind the breaking change, it's for the better and we're still in preview, so break it! 😄 |
I vote for the breaking change. |
@pranavkm @SteveSandersonMS - please give this a look over and make sure it all makes sense. |
- Updated all `[Parameter]` references in .cs, .razor and .cshtml files to be `public`. #8825
- Updated all `[Parameter]` references in .cs, .razor and .cshtml files to be `public`. #8825
- The newly added analyzer warns users if they try to assign another components parameter.It does sanity checks to ensure that 1. The property reference is indeed a component parameter 2. The property reference is from a component 3. The assignment is outside of the parameters type hierarchy. Aka, we don't warn users for setting a components parameter if it's in the same class. - Updated existing `ComponentsFacts` to add additional utility methods to properly interact with components. - Added tests to ensure we're analyzing all the goods properly. #8825
- Updated all `[Parameter]` references in .cs, .razor and .cshtml files to be `public`. #8825
- The newly added analyzer warns users if they try to assign another components parameter.It does sanity checks to ensure that 1. The property reference is indeed a component parameter 2. The property reference is from a component 3. The assignment is outside of the parameters type hierarchy. Aka, we don't warn users for setting a components parameter if it's in the same class. - Updated existing `ComponentsFacts` to add additional utility methods to properly interact with components. - Added tests to ensure we're analyzing all the goods properly. #8825
All required items for this have been completed. |
- Prior to this a user could have private, protected or public parameters. We now require public and plan to update analyzers to enforce good usage of public component parameters. - Removed private `ComponentTagHelperDescriptorProvider` workaround. meta data workaround since we no longer operate on private parameters. - Updated existing tests to not have private parameter setters. I missed these in my last pass. - Added two new tests to validate parameters which are private or have private setters are ignored. dotnet/aspnetcore#8825
Summary
We have to make a final decision about the visibility of component parameters. We've run into many issues trying to use non-public properties, and I don't think these are going to stop.
Problems and Goals
TLDR we have given non-public properties a try and the results aren't great. We got here because we now have to maintain ref assembly code for our components manually. It would be great if the guidance for users worked for us as well.
Some options
We could recommend that users use public get properties, and we will call the setter regardless of its visibility.
We could recommend that users use public get/set properties and we will write an analyzer to tell you not to set component parameter properties.
I don't like the option that we'd keep on doing analysis over non-public properties. We don't do this anywhere else I can think of, and I don't have confidence that this will play out in our favor wrt tooling.
Conclusion
We have a conclusion here!
Preview 8
.Components
[CascadingParameter]s
do not get Analyzesr warnings impacted[Parameter]
Before final release
We can leave
[CascadingParameter]
properties alone. They don't interact with tooling, don't want documentation, and don't represent a public contract.The text was updated successfully, but these errors were encountered: