John Vishnefske
Example full stack .NET application. Console client (targeting .NET 8.0) consuming an ASP.NET Core gRPC API with a SQL backend. The API is designed to run on Linux.
-
- Database Setup: The
ContactsApinow uses SQLite. The database file (contacts.db) will be automatically created and initialized with necessary tables (Contacts, Prefixes, Suffixes) and initial lookup data when the API starts for the first time. No manual setup is required.
- Database Setup: The
-
- API Configuration: The
ContactsApi's database connection string is now configured inappsettings.jsonunder theConnectionStrings:DefaultConnectionkey. TheUtilitiesclass is now a service that reads this configuration. Ensure the gRPC endpoint is correctly exposed (e.g.,https://localhost:7001).
- API Configuration: The
-
- Client Configuration: The
Clientconsole application's gRPC endpoint address is now configurable viaClient/App.configunder theGrpcApiAddresskey.
- Client Configuration: The
-
- Clean Build: Achieve a build with zero errors and zero warnings across all projects.
-
- Error Handling & Logging: Enhanced error handling and structured logging have been implemented:
- API:
ContactsGrpcServiceandLookupsGrpcServicenow includetry-catchblocks to handle exceptions from theUtilitieslayer, logging errors and returning appropriateRpcExceptionstatuses (e.g.,StatusCode.Internal,StatusCode.NotFound).Utilitiesalso logs its operations. - Client:
Client/Program.csnow includestry-catchblocks around gRPC calls to catchRpcExceptionand display user-friendly error messages. - Logging Configuration:
ContactsApi/Program.csis configured for console and debug logging.
-
- User Interface: The current client is a console application. If a graphical user interface (GUI) is desired, a new client project would need to be developed using a cross-platform UI framework (e.g., Avalonia UI, .NET MAUI). (Out of Scope for this request)
-
- Testing:
-
- Unit Testing: Unit tests are implemented for
ContactsApi's persistence layer (UtilitiesTests.cs) and gRPC services (ContactsGrpcServiceTests.cs,LookupsGrpcServiceTests.cs). These tests mock dependencies and useTestServerCallContextfor isolated testing of service logic.IConfigurationmocking has been made robust usingConfigurationBuilder.AddInMemoryCollection().
- Unit Testing: Unit tests are implemented for
-
- Integration Testing: A new
ContactsApi.Tests/IntegrationTests.csclass has been added. It usesMicrosoft.AspNetCore.Mvc.Testingto host theContactsApiin an in-memory test server andGrpc.Net.ClientFactoryto create gRPC clients, allowing for end-to-end testing of the API.
- Integration Testing: A new
-
- Deployment: Add basic instructions for deploying the
ContactsApito a Linux environment (e.g., Docker, Kestrel behind Nginx) and theClientconsole application. (Documentation Task)
- Deployment: Add basic instructions for deploying the
- Best Practices for Simplicity:
-
- Asynchronous Programming: Ensure all I/O-bound and long-running operations are truly asynchronous to avoid blocking calls and simplify concurrent execution flow.
-
- Minimize Exceptions for Control Flow: Exceptions are used only for truly exceptional conditions (e.g., missing configuration, unexpected database errors), not for normal program flow (e.g.,
GetContactreturnsnullor throwsRpcException.NotFound).
- Minimize Exceptions for Control Flow: Exceptions are used only for truly exceptional conditions (e.g., missing configuration, unexpected database errors), not for normal program flow (e.g.,
-
- Offload Long-Running Tasks: This is not directly applicable to the current simple CRUD operations, as they are primarily I/O-bound and handled asynchronously.
-
- Correct Context and Service Lifetime Management:
HttpContextis no longer relevant in the gRPC context.Utilitiesis registered as a singleton, ensuring a single instance manages database connections efficiently.
- Correct Context and Service Lifetime Management:
-
- Efficient Data Retrieval: Retrieve only the necessary data from the database to simplify data models and reduce processing overhead. (General guideline, no specific code changes planned unless clear inefficiency is found).
-