aws-lambda-dotnet icon indicating copy to clipboard operation
aws-lambda-dotnet copied to clipboard

Amazon.Lambda.Annotations: allow an alternate IServiceProvider implementation

Open chrischappell-rgare opened this issue 10 months ago • 4 comments

Describe the feature

Provide a way of using an inversion of control container other than the default Microsoft.Extensions.DependencyInjection.

Use Case

I would like to be able to use Autofac with Amazon.Lambda.Annotations.

Proposed Solution

A formal api around a Startup class would work, but it looks like a small tweak to the generated code may be sufficient to hook in an alternate IServiceProvider.

The serviceProvider is currently stored in a field defined like this: private readonly ServiceProvider serviceProvider;

The field is using the concrete type ServiceProvider. If the field type were changed to IServiceProvider that would allow a different IServiceProvider to be used by implementing a BuildServiceProvider extension method in the Lambda project.

public static AutofacServiceProvider BuildServiceProvider(this IServiceCollection services)
{
      var builder = new ContainerBuilder();
      builder.Populate(services);
      return new AutofacServiceProvider(builder.Build());
}

Other Information

No response

Acknowledgements

  • [ ] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

AWS .NET SDK and/or Package version used

Amazon.Lambda.Annotations 1.3.0

Targeted .NET Platform

.Net 8

Operating System and version

AmazonLinux

chrischappell-rgare avatar Apr 12 '24 18:04 chrischappell-rgare