aws / aws/aws-lambda-dotnet

Amazon.Lambda.Annotations: allow an alternate IServiceProvider implementation

Open
#1,729 5 comments 1 reaction 0 assignees View on GitHub
annotations feature-request p2 queued
Dominant language
C#
Stars
1.7k
Forks
503
Avg merge
1d 5h
Merged PRs (30d)
18

Description

### 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.