From 6c6b793fefe8a42402bbca735b9e884cb4feb34f Mon Sep 17 00:00:00 2001 From: webreidi Date: Fri, 27 Jun 2025 08:54:16 -0700 Subject: [PATCH 1/2] Add guidelines for C# development and MAUI patterns --- instructions/blazor.md | 2 +- instructions/csharp.md | 113 ++++++++++++++++++++++++++++++++++++ instructions/dotnet-maui.md | 67 +++++++++++++++++++++ 3 files changed, 181 insertions(+), 1 deletion(-) create mode 100644 instructions/csharp.md create mode 100644 instructions/dotnet-maui.md diff --git a/instructions/blazor.md b/instructions/blazor.md index 74642b3..c9aa40d 100644 --- a/instructions/blazor.md +++ b/instructions/blazor.md @@ -23,7 +23,7 @@ appliesTo: "**/*.razor, **/*.cs" - Use data binding effectively with @bind. - Leverage Dependency Injection for services in Blazor. - Structure Blazor components and services following Separation of Concerns. -- Use C# 10+ features like record types, pattern matching, and global usings. +- Always use the latest version C#, currently C# 13 features like record types, pattern matching, and global usings. ## Error Handling and Validation diff --git a/instructions/csharp.md b/instructions/csharp.md new file mode 100644 index 0000000..c12d7aa --- /dev/null +++ b/instructions/csharp.md @@ -0,0 +1,113 @@ +--- +description: Guidelines for building C# applications +--- + +# C# Development + +## C# Instructions +- Always use the latest version C#, currently C# 13 features. +- Write clear and concise comments for each function. + +## General Instructions +- Make only high confidence suggestions when reviewing code changes. +- Write code with good maintainability practices, including comments on why certain design decisions were made. +- Handle edge cases and write clear exception handling. +- For libraries or external dependencies, mention their usage and purpose in comments. + +## Naming Conventions + +- Follow PascalCase for component names, method names, and public members. +- Use camelCase for private fields and local variables. +- Prefix interface names with "I" (e.g., IUserService). + +## Formatting + +- Apply code-formatting style defined in `.editorconfig`. +- Prefer file-scoped namespace declarations and single-line using directives. +- Insert a newline before the opening curly brace of any code block (e.g., after `if`, `for`, `while`, `foreach`, `using`, `try`, etc.). +- Ensure that the final return statement of a method is on its own line. +- Use pattern matching and switch expressions wherever possible. +- Use `nameof` instead of string literals when referring to member names. +- Ensure that XML doc comments are created for any public APIs. When applicable, include `` and `` documentation in the comments. + +## Project Setup and Structure + +- Guide users through creating a new .NET project with the appropriate templates. +- Explain the purpose of each generated file and folder to build understanding of the project structure. +- Demonstrate how to organize code using feature folders or domain-driven design principles. +- Show proper separation of concerns with models, services, and data access layers. +- Explain the Program.cs and configuration system in ASP.NET Core 9 including environment-specific settings. + +## Nullable Reference Types + +- Declare variables non-nullable, and check for `null` at entry points. +- Always use `is null` or `is not null` instead of `== null` or `!= null`. +- Trust the C# null annotations and don't add null checks when the type system says a value cannot be null. + +## Data Access Patterns + +- Guide the implementation of a data access layer using Entity Framework Core. +- Explain different options (SQL Server, SQLite, In-Memory) for development and production. +- Demonstrate repository pattern implementation and when it's beneficial. +- Show how to implement database migrations and data seeding. +- Explain efficient query patterns to avoid common performance issues. + +## Authentication and Authorization + +- Guide users through implementing authentication using JWT Bearer tokens. +- Explain OAuth 2.0 and OpenID Connect concepts as they relate to ASP.NET Core. +- Show how to implement role-based and policy-based authorization. +- Demonstrate integration with Microsoft Entra ID (formerly Azure AD). +- Explain how to secure both controller-based and Minimal APIs consistently. + +## Validation and Error Handling + +- Guide the implementation of model validation using data annotations and FluentValidation. +- Explain the validation pipeline and how to customize validation responses. +- Demonstrate a global exception handling strategy using middleware. +- Show how to create consistent error responses across the API. +- Explain problem details (RFC 7807) implementation for standardized error responses. + +## API Versioning and Documentation + +- Guide users through implementing and explaining API versioning strategies. +- Demonstrate Swagger/OpenAPI implementation with proper documentation. +- Show how to document endpoints, parameters, responses, and authentication. +- Explain versioning in both controller-based and Minimal APIs. +- Guide users on creating meaningful API documentation that helps consumers. + +## Logging and Monitoring + +- Guide the implementation of structured logging using Serilog or other providers. +- Explain the logging levels and when to use each. +- Demonstrate integration with Application Insights for telemetry collection. +- Show how to implement custom telemetry and correlation IDs for request tracking. +- Explain how to monitor API performance, errors, and usage patterns. + +## Testing + +- Always include test cases for critical paths of the application. +- Guide users through creating unit tests. +- Do not emit "Act", "Arrange" or "Assert" comments. +- Copy existing style in nearby files for test method names and capitalization. +- Explain integration testing approaches for API endpoints. +- Demonstrate how to mock dependencies for effective testing. +- Show how to test authentication and authorization logic. +- Explain test-driven development principles as applied to API development. + +## Performance Optimization + +- Guide users on implementing caching strategies (in-memory, distributed, response caching). +- Explain asynchronous programming patterns and why they matter for API performance. +- Demonstrate pagination, filtering, and sorting for large data sets. +- Show how to implement compression and other performance optimizations. +- Explain how to measure and benchmark API performance. + +## Deployment and DevOps + +- Guide users through containerizing their API using .NET's built-in container support (`dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer`). +- Explain the differences between manual Dockerfile creation and .NET's container publishing features. +- Explain CI/CD pipelines for NET applications. +- Demonstrate deployment to Azure App Service, Azure Container Apps, or other hosting options. +- Show how to implement health checks and readiness probes. +- Explain environment-specific configurations for different deployment stages. diff --git a/instructions/dotnet-maui.md b/instructions/dotnet-maui.md new file mode 100644 index 0000000..e5e7e41 --- /dev/null +++ b/instructions/dotnet-maui.md @@ -0,0 +1,67 @@ +--- +description: MAUI component and application patterns +appliesTo: "**/*.xaml, **/*.cs" +--- + +## MAUI Code Style and Structure + +- Write idiomatic and efficient MAUI and C# code. +- Follow .NET and MAUI conventions. +- Prefer inline functions for smaller components but separate complex logic into code-behind or service classes. +- Async/await should be used where applicable to ensure non-blocking UI operations. + +## Naming Conventions + +- Follow PascalCase for component names, method names, and public members. +- Use camelCase for private fields and local variables. +- Prefix interface names with "I" (e.g., IUserService). + +## MAUI and .NET Specific Guidelines + +- Utilize MAUI's built-in features for component lifecycle (e.g. OnAppearing, OnDisappearing). +- Use data binding effectively with {Binding}. +- Structure MAUI components and services following Separation of Concerns. +- Always use the latest version C#, currently C# 13 features like record types, pattern matching, and global usings. + +## Error Handling and Validation + +- Implement proper error handling for MAUI pages and API calls. +- Use logging for error tracking in the backend and consider capturing UI-level errors in MAUI with tools like MAUI Community Toolkit's Logger. +- Implement validation using FluentValidation or DataAnnotations in forms. + +## MAUI API and Performance Optimization + +- Utilize MAUI's built-in features for component lifecycle (e.g. OnAppearing, OnDisappearing). +- Use asynchronous methods (async/await) for API calls or UI actions that could block the main thread. +- Optimize MAUI components by reducing unnecessary renders and using OnPropertyChanged() efficiently. +- Minimize the component render tree by avoiding re-renders unless necessary, using BatchBegin() and BatchCommit() where appropriate. + +## Caching Strategies + +- Implement in-memory caching for frequently used data, especially for MAUI apps. Use IMemoryCache for lightweight caching solutions. +- Consider Distributed Cache strategies (like Redis or SQL Server Cache) for larger applications that need shared state across multiple users or clients. +- Cache API calls by storing responses to avoid redundant calls when data is unlikely to change, thus improving the user experience. + +## State Management Libraries + +- Use dependency injection and the .NET MAUI Community Toolkit for state sharing across components. + +## API Design and Integration + +- Use HttpClient or other appropriate services to communicate with external APIs or your own backend. +- Implement error handling for API calls using try-catch and provide proper user feedback in the UI. + +## Testing and Debugging + +- Test components and services using xUnit, NUnit, or MSTest. +- Use Moq or NSubstitute for mocking dependencies during tests. + +## Security and Authentication + +- Implement Authentication and Authorization in the MAUI app where necessary using OAuth or JWT tokens for API authentication. +- Use HTTPS for all web communication and ensure proper CORS policies are implemented. + +## API Documentation and Swagger + +- Use Swagger/OpenAPI for API documentation for your backend API services. +- Ensure XML documentation for models and API methods for enhancing Swagger documentation. From f7f6ac7d3d1eb3374ef8ed1edd495f90f29169fa Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Wed, 2 Jul 2025 17:55:56 +1000 Subject: [PATCH 2/2] Fixing README from merge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 59584ae..2a9435e 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ Team and project-specific instructions to enhance GitHub Copilot's behavior for - [Blazor](instructions/blazor.md) - Blazor component and application patterns - [Cmake Vcpkg](instructions/cmake-vcpkg.md) - C++ project configuration and package management - [Copilot Process tracking Instructions](instructions/copilot-thought-logging.instructions.md) - See process Copilot is following where you can edit this to reshape the interaction or save when follow up may be needed +- [C# Development](instructions/csharp.md) - Guidelines for building C# applications +- [Dotnet Maui](instructions/dotnet-maui.md) - MAUI component and application patterns - [Genaiscript](instructions/genaiscript.md) - AI-powered script generation guidelines - [Generate Modern Terraform Code For Azure](instructions/generate-modern-terraform-code-for-azure.md) - Guidelines for generating modern Terraform code for Azure - [Markdown](instructions/markdown.md) - Documentation and content creation standards