Skip to content

Instantly share code, notes, and snippets.

@gistlyn
Created November 11, 2021 14:56
Show Gist options
  • Save gistlyn/32810f81c3164c1dbd31d4100972054a to your computer and use it in GitHub Desktop.
Save gistlyn/32810f81c3164c1dbd31d4100972054a to your computer and use it in GitHub Desktop.
Use AWS DynamoDB and PocoDynamo
dotnet add package ServiceStack.Aws
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using ServiceStack;
using ServiceStack.Aws;
using ServiceStack.Aws.DynamoDb;
using Amazon;
using Amazon.DynamoDBv2;
[assembly: HostingStartup(typeof(MyApp.ConfigureDynamoDb))]
namespace MyApp
{
public class ConfigureDynamoDb : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) => {
var awsDb = new AmazonDynamoDBClient("keyId","key", new AmazonDynamoDBConfig {
ServiceURL = context.Configuration.GetConnectionString("DynamoDb") ?? "http://localhost:8000"
});
var db = new PocoDynamo(awsDb);
services.AddSingleton<IAmazonDynamoDB>(awsDb);
services.AddSingleton<IPocoDynamo>(db);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment