I have a .NET Core API Gateway based project. I want to introduce dependency injection (di) as many of the packages that I need to introduce are based on this pattern, so require the use of IServiceCollection and so on.
The examples I can find online of introducing DI to AWS Lambda focus only on the standard Lambda projects, where the entry point is the Handler function. I'm unsure how to replicate this with my API Gateway project, as it uses a different structure. I have one parameterless constructor of
Public Functions()
{}
And many instances of
public async Task<APIGatewayProxyResponse> MyProxyResponse(APIGatewayProxyRequest request, ILambdaContext context)
{
}
I'm not clear on how to introduce DI to this project. For instance, take the .NET Core MemCached package which is detailed here https://github.com/cnblogs/EnyimMemcachedCore
I can set up the following:
public class Functions
{
public IConfiguration Configuration { get; private set; }
private void ConfigureServices(IServiceCollection serviceCollection)
{
serviceCollection.AddEnyimMemcached();
serviceCollection.AddEnyimMemcached(options => options.AddServer(Environment.GetEnvironmentVariable("CACHE_URL"),
Convert.ToInt32(Environment.GetEnvironmentVariable("CACHE_PORT"))));
// TODO: Register services with DI system
}
private readonly AmazonSimpleSystemsManagementClient _systemsManagementClient;
private readonly JSchema _jSchema;
private readonly loyaltyContext _loyaltyContext;
private readonly IMemcachedClient _memcachedClientv2;
But _memcachedClientv2 is never assigned to, so it's value will be null. I'm not sure how to get from the above, to a working _memcachedClientv2 within each APIGatewayProxyRequest method.