steering_docs/dotnet-tech/wrapper.md
šØ CRITICAL - Must be completed BEFORE any code generation
# Step 1: List available knowledge bases
ListKnowledgeBases()
# Step 2: Query coding standards (REQUIRED)
QueryKnowledgeBases("coding-standards-KB", "dotnet-code-example-standards")
# Step 3: Query implementation patterns (REQUIRED)
QueryKnowledgeBases("dotnet-premium-KB", ".NET implementation patterns")
# Step 4: AWS service research (REQUIRED)
search_documentation("What is [AWS Service] and what are its key API operations?")
read_documentation("https://docs.aws.amazon.com/[service]/latest/[relevant-page]")
FAILURE TO COMPLETE KNOWLEDGE BASE CONSULTATION WILL RESULT IN INCORRECT CODE STRUCTURE
Generate service wrapper classes that encapsulate AWS service functionality with proper error handling and logging.
dotnetv4/{Service}/Actions/
āāā {Service}Wrapper.cs # Service wrapper class
āāā {Service}Wrapper.csproj # Project file
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Amazon.{Service};
using Amazon.{Service}.Model;
using Amazon.{ServiceDataAPI};
using Amazon.{ServiceDataAPI}.Model;
namespace {Service}Actions;
// snippet-start:[{Service}.dotnetv4.{Service}Wrapper]
/// <summary>
/// Wrapper class for Amazon {Service} operations.
/// </summary>
public class {Service}Wrapper
{
private readonly Amazon{Service}Client _{service}Client;
private readonly Amazon{ServiceDataAPI}Client _{service}DataClient;
/// <summary>
/// Constructor for {Service}Wrapper.
/// </summary>
/// <param name="{service}Client">Amazon {Service} client.</param>
/// <param name="{service}DataClient">Amazon {Service} Data API client.</param>
public {Service}Wrapper(Amazon{Service}Client {service}Client, Amazon{ServiceDataAPI}Client {service}DataClient)
{
_{service}Client = {service}Client;
_{service}DataClient = {service}DataClient;
}
// Individual action methods follow...
}
// snippet-end:[{Service}.dotnetv4.{Service}Wrapper]
Key Changes:
## Action Method Pattern
```csharp
// snippet-start:[{Service}.dotnetv4.{ActionName}]
/// <summary>
/// {Action description}.
/// </summary>
/// <param name="param">Parameter description.</param>
/// <returns>Response description.</returns>
public async Task<{ReturnType}> {ActionMethod}Async(string param)
{
try
{
var request = new {ActionName}Request
{
Parameter = param
};
var response = await _{service}Client.{ActionName}Async(request);
Console.WriteLine($"{Action} completed successfully");
return response.{Property};
}
catch (Exception ex)
{
Console.WriteLine($"Error in {ActionName}: {ex.Message}");
throw;
}
}
// snippet-end:[{Service}.dotnetv4.{ActionName}]
Key Changes:
// snippet-start:[{Service}.dotnetv4.List{Resources}]
/// <summary>
/// Lists all {resources} using pagination to retrieve complete results.
/// </summary>
/// <returns>A list of all {resources}.</returns>
public async Task<List<{Resource}>> List{Resources}Async()
{
try
{
var {resources} = new List<{Resource}>();
var {resources}Paginator = _{service}Client.Paginators.List{Resources}(new List{Resources}Request());
await foreach (var response in {resources}Paginator.Responses)
{
{resources}.AddRange(response.{Resources});
}
_logger.LogInformation("Retrieved {Count} {resources}", {resources}.Count);
return {resources};
}
catch (Amazon{Service}Exception ex)
{
var errorCode = ex.ErrorCode;
if (errorCode == "BadRequestException")
{
_logger.LogError("Invalid request parameters for listing {resources}");
}
else
{
_logger.LogError("Error listing {resources}: {Message}", ex.Message);
}
throw;
}
}
// snippet-end:[{Service}.dotnetv4.List{Resources}]
// snippet-start:[{Service}.dotnetv4.List{Resources}WithFilterSteering]
/// <summary>
/// Lists {resources} with optional filtering, using pagination.
/// </summary>
/// <param name="filterCriteria">Optional criteria to filter results.</param>
/// <returns>A list of filtered {resources}.</returns>
public async Task<List<{Resource}>> List{Resources}WithFilterAsync(FilterCriteria? filterCriteria = null)
{
try
{
var request = new List{Resources}Request();
if (filterCriteria != null)
{
request.FilterCriteria = filterCriteria;
}
var {resources} = new List<{Resource}>();
var {resources}Paginator = _{service}Client.Paginators.List{Resources}(request);
await foreach (var response in {resources}Paginator.Responses)
{
{resources}.AddRange(response.{Resources});
}
_logger.LogInformation("Retrieved {Count} filtered {resources}", {resources}.Count);
return {resources};
}
catch (Amazon{Service}Exception ex)
{
_logger.LogError("Error listing {resources} with filter: {Message}", ex.Message);
throw;
}
}
// snippet-end:[{Service}.dotnetv4.List{Resources}WithFilterSteering]
Based on the service specification, handle these error types:
try
{
var response = await _{service}Client.OperationAsync();
return response;
}
catch (Amazon{Service}Exception ex)
{
var errorCode = ex.ErrorCode;
if (errorCode == "BadRequestException")
{
_logger.LogError("Validate input parameters and notify user");
}
else if (errorCode == "InternalServerErrorException")
{
_logger.LogError("Retry operation with exponential backoff");
}
else
{
_logger.LogError("Error in operation: {Message}", ex.Message);
}
throw;
}
FromClient() static methodListBucketsAsync for ListBuckets)await foreachvar allItems = new List<Item>();
var itemsPaginator = _client.Paginators.ListItems(new ListItemsRequest());
await foreach (var response in itemsPaginator.Responses)
{
allItems.AddRange(response.Items);
}
ListBuckets ā Use pagination if availableListObjects ā Always use pagination (can return thousands of objects)ListTables ā Use pagination for complete resultsDescribeInstances ā Use pagination for large environmentsListFunctions ā Use pagination for complete function listCRITICAL: Use the correct snippet tag format for all code examples:
// ā
CORRECT - Service name first, then dotnetv4
// snippet-start:[{Service}.dotnetv4.CreateClusterSteering]
public async Task<Cluster> CreateClusterAsync(...)
{
// Implementation
}
// snippet-end:[{Service}.dotnetv4.CreateClusterSteering]
// ā WRONG - Old format
// snippet-start:[dotnetv4.example_code.{Service}.CreateClusterSteering]
// snippet-end:[dotnetv4.example_code.{Service}.CreateClusterSteering]
Format: [{Service}.dotnetv4.{ActionName}]
.dotnetv4.