![]() Let's assume you have created a Table in AWS and have access & secret keys. ![]() Inject it in your Startup like this var client = Configuration.GetAWSOptions(). In this blog, we are going to connect & query DynamoDB using. Public async Task DeleteByIdAsync(T item) Public async Task GetByIdAsync(string id) Public DynamoDbContext(IAmazonDynamoDB client) Services.AddDefaultAWSOptions(Configuration.GetAWSOptions()) īasically you'd have to create an interface for your DynamoDB context public interface IDynamoDbContext : IDisposable where T : classĬreate a class implementing the interface public class DynamoDbContext : DynamoDBContext, IDynamoDbContext Public void ConfigureServices(IServiceCollection services) Public ValuesController(IDynamoDBContext context) Access Amazon DynamoDB NoSQL database from reporting tools, databases, and custom applications Our Drivers make integration a snap, providing an easy-to-use database-like interface to Amazon. Private readonly IDynamoDBContext context With such approach IDynamoDBContext gets injected into ValuesController: public class ValuesController The proper way is to register DynamoDBContext in DI container and let the container itself create an instance when it's required. You'll face a problems when it comes to unit testing your code, because you have no way to substitute implementation of DynamoDBContext. You're not using Dependency Injection for DynamoDBContext and create its instance in controller constructor through new operator. Is there a way to create an instance of the context in theĬonfigureServices method and add it to the project there, or is theĪlthough your solution will work, it has a drawback.
0 Comments
Leave a Reply. |