Skip to content

Conversation

@brokenthorn
Copy link
Contributor

Non-constant fields should not be visible.

Summary

Proposes a fix in accordance with .NET code analysis usage rule: https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca2211

Cause

A public or protected static field is not constant nor is it read-only.

Rule description

Static fields that are neither constants nor read-only are not thread-safe. Access to such a field must be carefully controlled and requires advanced programming techniques for synchronizing access to the class object. Because these are difficult skills to learn and master, and testing such an object poses its own challenges, static fields are best used to store data that does not change. This rule applies to libraries; applications should not expose any fields.

Non-constant fields should not be visible.
Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, we'll :shipit: - thank you 🙏

@IEvangelist IEvangelist merged commit 17c53de into dotnet:main May 5, 2021
@adegeo
Copy link
Contributor

adegeo commented May 13, 2021

@IEvangelist I think we need to be more cautious when accepting PRs into the architecture guidelines. This change broke the GetAll method in the base class as it doesn't return the members anymore since they were converted from fields to properties. Also, the sample project is out of date now: https://github.com/dotnet-architecture/eShopOnContainers/blob/dev/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs

@IEvangelist
Copy link
Member

@IEvangelist David Pine FTE I think we need to be more cautious when accepting PRs into the architecture guidelines. This change broke the GetAll method in the base class as it doesn't return the members anymore since they were converted from fields to properties. Also, the sample project is out of date now: https://github.com/dotnet-architecture/eShopOnContainers/blob/dev/src/Services/Ordering/Ordering.Domain/AggregatesModel/BuyerAggregate/CardType.cs

@adegeo That's a good call out, in hind site that is a breaking change. When I reviewed I did look around at its usage and it seemed accurate at the time. See #24236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants