Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Best way to inject instance of DynamoDBContext in .NET Core

$
0
0

Currently working on a web services project for my class and have decided to make a web API using .NET Core and DynamodDB.

I was just curious what the best way to inject the DynamoDBContext is?

I currently am doing it like this:

public void ConfigureServices(IServiceCollection services){    services.AddMvc();    services.AddDefaultAWSOptions(Configuration.GetAWSOptions());    services.AddAWSService<IAmazonDynamoDB>();}

I got this piece of code above from the DynamoDB documentation. I add an instance of IAmazonDynamoDB to the project.

DynamoDBContext context;public ValuesController(IAmazonDynamoDB context){    this.context = new DynamoDBContext(context);}

In the controller, I then inject the IAmazonDynamoDB instance, and use that to create an instance of DynamoDBContext.

Is there a way to create an instance of the context in the ConfigureServices method and add it to the project there, or is the way I am doing it currently fine?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>