Skip to content

Commit b04d123

Browse files
authored
Merge pull request #113 from gothinkster/updates-8-x
Updates for 8.x
2 parents bd8ff24 + 83f65f6 commit b04d123

38 files changed

+761
-411
lines changed

.config/dotnet-tools.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"csharpier": {
6-
"version": "0.28.0",
6+
"version": "1.0.3",
77
"commands": [
8-
"dotnet-csharpier"
9-
]
8+
"csharpier"
9+
],
10+
"rollForward": false
1011
}
1112
}
1213
}

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,6 @@ Dockerfile
282282

283283
# .env file contains default environment variables for docker
284284
.env
285-
.git/
285+
.git/
286+
bin/
287+
obj/
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# C# Coding Standards and Best Practices
2+
3+
## Code Style
4+
5+
- **MANDATORY**: Follow the .NET coding conventions as defined by Microsoft.
6+
- **ALWAYS** use `camelCase` for local variables and method parameters.
7+
- **ALWAYS** use `PascalCase` for method names, property names, and class names.
8+
- **MANDATORY**: Ensure that braces are used consistently for all control structures. Example:
9+
```csharp
10+
if (x == y)
11+
{
12+
Foo();
13+
}
14+
```
15+
- **ALWAYS** keep lines of code reasonably short; lines should not exceed 120 characters.
16+
17+
## Naming Conventions
18+
19+
- **MANDATORY**: Use meaningful and descriptive names for classes, methods, and variables.
20+
- **NEVER** use abbreviated names unless they are well-known (e.g., `Id` for Identifier).
21+
- **REQUIRED**: Prefix interfaces with the letter `I`.
22+
- **ALWAYS** name namespaces starting with the company name followed by the project and any sub-folders aligning with the project structure.
23+
24+
## Error Handling
25+
26+
- **MANDATORY**: Use exceptions for abnormal or unexpected program behavior.
27+
- **ALWAYS** provide helpful error messages when throwing exceptions.
28+
- **NEVER** use exceptions for normal flow of control.
29+
- `recommended`: Prefer `try/catch` over returning error codes.
30+
31+
## Documentation
32+
33+
- **REQUIRED**: Every public class and method **MUST** have XML documentation comments for IntelliSense and documentation tools.
34+
- **MANDATORY**: Document all parameters, exceptions thrown, and return values.
35+
- `recommended`: Regularly update documentation to reflect changes in the codebase.
36+
37+
## Security
38+
39+
- **MUST** validate all inputs to avoid SQL injections and other common security threats.
40+
- **ALWAYS** use secure methods and classes provided by the .NET framework where available.
41+
- `recommended`: Utilize Code Analysis (FxCop) to detect security flaws.
42+
43+
## Performance
44+
45+
- **MANDATORY**: Avoid unnecessary object creation within loops.
46+
- `recommended`: Utilize lazy loading where appropriate.
47+
- `recommended`: Employ caching mechanisms to improve responsiveness and performance.
48+
49+
## Source Control
50+
51+
- **MANDATORY**: Check in code frequently to avoid large sets of unshared changes.
52+
- **REQUIRED**: Include meaningful commit messages with each check-in.
53+
- **NEVER** check in commented-out code or unnecessary files.
54+
55+
## Testing
56+
57+
- **MANDATORY**: Write unit tests for all new methods and classes.
58+
- **ALWAYS** run the full test suite before committing your code to the repository.
59+
- **REQUIRED**: Aim for at least 80% code coverage in tests for all business logic classes.
60+
61+
## API Design
62+
63+
- **MUST** ensure that public APIs are intuitive and well-documented.
64+
- **ALWAYS** use consistent parameter ordering across similar methods.
65+
- `recommended`: Avoid breaking changes to public APIs.
66+
67+
## Versioning
68+
69+
- **MANDATORY**: Adhere to semantic versioning rules for all public software releases.
70+
- **ALWAYS** increment version numbers based on the extent of changes:
71+
- **MAJOR** version when you make incompatible API changes,
72+
- **MINOR** version when you add functionality in a backward-compatible manner,
73+
- **PATCH** version when you make backward-compatible bug fixes.
74+
75+
## Dependability
76+
77+
- `recommended`: Rely on proven .NET libraries and frameworks rather than creating custom implementations.
78+
- **NEVER** ignore deprecation notices without assessing impact.
79+
80+
This set of rules defines the essential guidelines that **MUST**, **SHOULD**, and **NEVER** be violated in any professional C# project as of 2025. These standards are in place to ensure reliability, security, and maintainability of code.

.github/copilot-csharp-csharp.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# C# Coding Standards for AI Coding Assistant 'copilot'
2+
3+
## General Principles
4+
- **MANDATORY**: Adhere to the latest C# language version to ensure code uses the most current features and improvements.
5+
- **ALWAYS** write code that is clear, understandable, and maintainable.
6+
- **NEVER** use obsolete or deprecated C# features unless absolutely necessary for maintaining legacy systems.
7+
8+
## Formatting and Style
9+
- **MUST** follow Microsoft's C# coding conventions regarding naming, layout, and commenting.
10+
- Use PascalCase for class names and method names.
11+
- Use camelCase for local variables and method arguments.
12+
- **REQUIRED**: Place opening braces on a new line for classes, methods, and control statements.
13+
- **ALWAYS** indent code blocks with four spaces, not tabs.
14+
- **ALWAYS** use explicit typing over implicit var declarations, except in cases of obvious typing (e.g., instantiation).
15+
16+
## Error Handling
17+
- **MANDATORY**: Handle all possible exceptions using try, catch, finally blocks where applicable.
18+
- **NEVER** allow exceptions to go unhandled unless explicitly justified by the application logic.
19+
- Exceptions **SHOULD** be logged with a detailed error message and, if applicable, stack trace.
20+
21+
## Security Practices
22+
- **MUST** validate all inputs to prevent injection attacks and ensure data integrity.
23+
- **REQUIRED**: Utilize secure methods and libraries for handling sensitive data such as passwords, API keys, and personal user information.
24+
- **NEVER** log sensitive information.
25+
26+
## Performance
27+
- **USE** async and await for asynchronous programming to improve application responsiveness and scalability.
28+
- **RECOMMENDED**: Optimize LINQ queries by minimizing data fetching and processing operations.
29+
- **SHOULD** prefer StringBuilder over string concatenation in loops or during extensive string manipulations.
30+
31+
## Testing
32+
- **MANDATORY**: Write unit tests for all business logic to ensure code quality and catch regressions early.
33+
- Unit tests **SHOULD** cover both positive and negative scenarios.
34+
- **ALWAYS** use a consistent test naming convention that clearly describes the test purpose.
35+
36+
## Code Reviews and Collaboration
37+
- **MUST** use pull requests for merging code into shared branches and repositories.
38+
- **ALWAYS** perform thorough code reviews to catch issues early and share knowledge among team members.
39+
- **REQUIRED**: Follow a defined Git workflow suitable for your team structure (e.g., Git flow, GitHub flow).
40+
41+
## Documentation
42+
- **REQUIRED**: Document all public classes, methods, properties, and enums.
43+
- **ALWAYS** update documentation to reflect changes in the logic or implementation.
44+
- **SHOULD** include inline comments to clarify complex code blocks.
45+
46+
## Dependency Management
47+
- **MANDATORY**: Keep external dependencies to a minimum to reduce potential security risks and lower the maintenance burden.
48+
- **ALWAYS** audit dependencies for security vulnerabilities on a regular schedule.
49+
- When new libraries are added, **SHOULD** assess their stability and support level.
50+
51+
## Continuous Integration/Continuous Deployment
52+
- **MUST** have CI/CD pipelines in place to automate testing and deployment processes.
53+
- Deployment scripts **SHOULD** be tested regularly to prevent deployment failures.
54+
55+
## Legacy Code and Migration
56+
- **ALWAYS** aim to incrementally refactor legacy code as part of ongoing development.
57+
- When dealing with legacy systems, **SHOULD** plan a clear migration path towards newer technologies or frameworks.
58+
59+
These rules are designed to ensure that the AI coding assistant 'copilot' and its users adhere to the best practices and modern standards prevalent in C# development as of 2025.

.github/copilot-csharp-docker.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# C# Project Rules: Docker Integration
2+
3+
## General Docker Practices
4+
5+
- **MANDATORY**: All Dockerfiles **MUST** be located in the root of the project repository.
6+
- **MANDATORY**: Docker images **MUST** be built using official .NET base images from Docker Hub unless a specific need dictates otherwise.
7+
8+
## Dockerfile Configuration
9+
10+
- **REQUIRED**: The base image in the Dockerfile **MUST** match the .NET version used in the project.
11+
- **ALWAYS** use multi-stage builds to reduce the size of the final Docker image.
12+
- The `build-env` for compiling the application.
13+
- The `runtime-env` for the execution environment.
14+
- **NEVER** leave API keys, secrets, or other sensitive data in the Docker image.
15+
- **MANDATORY**: Docker build context **SHOULD** be kept as small as possible by properly setting `.dockerignore` files.
16+
- Environment variables **SHOULD** be used for application configurations that vary between environments (e.g., Development, Testing, Production).
17+
18+
## Docker Compose Configurations
19+
20+
- **REQUIRED**: Use Docker Compose for managing multi-container Docker applications.
21+
- **ALWAYS** define service dependencies explicitly in `docker-compose.yml`.
22+
- **MANDATORY**: Version of Docker Compose file **MUST** align with the latest supported Docker Engine and Compose specifications as of 2025.
23+
24+
## CI/CD Integrations
25+
26+
- **REQUIRED**: Integrate Docker builds into your CI/CD pipeline.
27+
- **MANDATORY**: Pull requests **MUST NOT** be merged unless the Docker image builds successfully.
28+
- **ALWAYS** tag Docker images with both a unique build tag and the `latest` tag in CI pipelines for easier rollback and deployment.
29+
30+
## Security Best Practices
31+
32+
- **MANDATORY**: Use Docker’s built-in security features such as `--cap-drop=all` and `readonly` filesystem where appropriate.
33+
- **MANDATORY**: Update the Docker images regularly to include the latest security patches for the base images and dependencies.
34+
- **ALWAYS** scan Docker images for vulnerabilities during CI/CD before pushing to a registry.
35+
- **REQUIRED**: Use private Docker registries for internal or sensitive projects.
36+
37+
## Performance Optimizations
38+
39+
- **MANDATORY**: Minimize the number of layers in Docker images where feasible by consolidating commands.
40+
- Images **SHOULD** leverage Docker cache layers by ordering Dockerfile instructions from least to most frequently changed.
41+
- **REQUIRED**: Performance critical settings, like CPU and memory limits, **MUST** be configured explicitly in Docker Compose configurations or Kubernetes deployment specs.
42+
43+
## Versioning and Tagging
44+
45+
- **MANDATORY**: Docker images **MUST** be versioned appropriately using semantic versioning principles.
46+
- **ALWAYS** use explicit version tags rather than relying on mutable tags like `latest` for production deployments.
47+
48+
By following these rules, the Docker integration for C# projects will adhere to modern standards and best practices as of 2025, ensuring efficiency, security, and maintainability.

.github/copilot-csharp-polyglot.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# C# Polyglot Coding Rules
2+
3+
## General Practices
4+
- **ALWAYS** use clear and descriptive variable names in English, as C# is most commonly written and maintained in English.
5+
- **MANDATORY**: Maintain consistent code style and conventions across different languages used in the project to ensure readability and maintainability.
6+
- Code documentation **MUST** be in English to support international teams and contributors.
7+
8+
## Handling Language Interoperability
9+
- **REQUIRED**: Ensure that all external libraries used for cross-language functionality are compatible with .NET standards.
10+
- **ALWAYS** encapsulate language-specific logic within boundary classes or namespaces.
11+
12+
## Error Handling
13+
- **MANDATORY**: Handle all cross-language operation errors gracefully, ensuring the errors are logged and user-friendly messages are displayed.
14+
- **ALWAYS** use try-catch blocks around code that calls into different programming languages.
15+
16+
## Security
17+
- **NEVER** expose direct interfaces of one language to another without appropriate security checks.
18+
- **MUST** validate all inputs when data crosses language boundaries to prevent injection attacks.
19+
20+
## Performance
21+
- **MANDATORY**: Optimize inter-language calls to minimize performance overhead.
22+
- **RECOMMENDED**: Profile and monitor performance when implementing cross-language functionality to identify bottlenecks.
23+
24+
## Testing
25+
- Integration tests **MUST** cover all polyglot components to ensure they work seamlessly together.
26+
- **REQUIRED**: Use mock objects and services to simulate interactions between different languages during unit testing.
27+
28+
## Continuous Integration
29+
- **MANDATORY**: Set up CI pipelines to build and test across all targeted languages.
30+
- Code reviews **SHOULD** focus on the integration points between different languages to catch potential issues early.

.github/copilot-csharp-security.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Security Rules for C# Projects
2+
3+
## General Security Practices
4+
- **MANDATORY** : Always validate and sanitize all user inputs to prevent SQL injections, cross-site scripting (XSS), and other injection attacks.
5+
- **MUST** : Employ strong, up-to-date cryptographic practices for data encryption, signing, and hashing.
6+
- **ALWAYS** : Ensure that error messages do not reveal details about the backend system, such as file paths or component versions.
7+
8+
## Authentication and Session Management
9+
- **MUST** : Implement secure authentication mechanisms like OAuth, OpenID Connect, or SAML.
10+
- **ALWAYS** : Use HTTPS and secure cookies (HttpOnly, Secure attributes) for session management.
11+
- **MANDATORY** : Implement multi-factor authentication for accessing sensitive data or operations.
12+
13+
## Authorization
14+
- **MUST** : Enforce the Principle of Least Privilege (PoLP) throughout the application.
15+
- **ALWAYS** : Use role-based access control (RBAC) or attribute-based access control (ABAC) to manage user permissions.
16+
17+
## Data Protection
18+
- **MANDATORY** : Encrypt sensitive data both at rest and in transit using industry-standard protocols and algorithms.
19+
- **MUST** : Properly manage and rotate keys and secrets using a secure vault solutions like Azure Key Vault or AWS Secrets Manager.
20+
21+
## Code Security
22+
- **NEVER** : Leave debug code or secrets (API keys, passwords) in the version control system.
23+
- **MANDATORY** : Use static code analysis tools to automatically detect and rectify security vulnerabilities in the codebase.
24+
- **ALWAYS** : Perform regular code reviews with a focus on security implications and vulnerabilities.
25+
26+
## External Dependencies
27+
- **REQUIRED** : Regularly update and patch all third-party libraries and frameworks to protect against known vulnerabilities.
28+
- **ALWAYS** : Vet external libraries for security vulnerabilities before including them in the project.
29+
30+
## Logging and Monitoring
31+
- **ALWAYS** : Implement logging and monitoring to detect and respond to security breaches or irregular activity.
32+
- **NEVER** : Log sensitive data like passwords or personal identification information.
33+
34+
## Network Security
35+
- **MUST** : Protect all network communications with TLS.
36+
- **ALWAYS** : Implement strong network isolation and segmentation strategies to limit the blast radius in case of a network intrusion.
37+
38+
## Incident Response
39+
- **REQUIRED** : Have an incident response plan that includes immediate actions, reporting to stakeholders, and remedial steps.
40+
- **MANDATORY** : Conduct regular security drills to ensure that all team members know their roles in case of a security incident.
41+
42+
## Compliance
43+
- **ALWAYS** : Adhere to relevant industry security standards and regulations, such as GDPR, PCI DSS, or HIPAA, depending on the project scope.
44+
- **MANDATORY** : Undergo regular security audits and compliance checks to maintain system integrity and trust.
45+
46+
By following these rules, C# projects can mitigate security risks and protect user data effectively.

.github/copilot-csharp-testing.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# C# Project Testing Guidelines
2+
3+
## General Principles
4+
5+
- **MANDATORY**: Use a recognized testing framework such as NUnit, xUnit, or MSTest for unit testing.
6+
- **ALWAYS** ensure each test case is independent and can be run in any order.
7+
- **REQUIRED**: Maintain a clean separation of test logic from production code.
8+
- **MUST** configure Continuous Integration (CI) to run tests automatically upon code pushes or pull requests.
9+
10+
## Writing Tests
11+
12+
### Structure
13+
14+
- **MANDATORY**: Structure tests logically using [Arrange-Act-Assert (AAA)](https://www.typemock.com/unit-test-patterns-for-net) pattern.
15+
- **MUST** name test methods clearly to reflect the behavior being tested.
16+
17+
### Assertions
18+
19+
- **MUST** use assertive statements that make the test purpose clear.
20+
- **REQUIRED**: Employ fluent assertions for more readable tests.
21+
22+
### Code Coverage
23+
24+
- **MANDATORY**: Aim for at least 80% code coverage to ensure most of the code is scrutinized by tests.
25+
- **RECOMMENDED**: Use tools such as Coverlet or Visual Studio Coverage tools to measure test coverage.
26+
27+
## Test Isolation
28+
29+
- **ALWAYS** use mocks and stubs to isolate the unit of work and avoid external dependencies in unit tests.
30+
- **MANDATORY**: Employ frameworks like Moq, NSubstitute, or FakeItEasy for mocking.
31+
32+
## Test Data
33+
34+
- **MUST** handle test data carefully, ensuring no leakage between tests.
35+
- **ALWAYS** prefer the use of in-memory databases like EF Core InMemory provider for integration testing.
36+
37+
## Performance
38+
39+
- **RECOMMENDED**: Regularly review and optimize the performance of test suites.
40+
- **SHOULD** avoid long-running tests in the primary test suite to keep the CI process efficient.
41+
42+
## Security
43+
44+
- **NEVER** use real data in testing environments to avoid risks of sensitive data exposure.
45+
- **ALWAYS** ensure tests validate input sanitation and adheres to security best practices.
46+
47+
## Documentation
48+
49+
- **REQUIRED**: Document the testing strategy and major choices in a TESTPLAN.md file.
50+
- Tests **SHOULD** include inline comments where necessary to explain complex logic or decisions.
51+
52+
## Error Handling
53+
54+
- **MANDATORY**: Tests **MUST** assert appropriate error handling in the application code and never ignore exceptions unless explicitly testing exception handling scenarios.
55+
56+
## Maintenance
57+
58+
- **NEVER** allow failing tests to accumulate or remain unfixed.
59+
- **SHOULD** regularly review and refactor tests to improve clarity and maintainability.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,5 @@ tools
286286

287287
# sqlite database
288288
*.db-shm
289-
*.db-wal
289+
*.db-wal
290+
*.db

.rules4rc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[settings]
2+
language = c#
3+
tags = best-practices,c#,docker,security,testing
4+
tools = copilot
5+

0 commit comments

Comments
 (0)