dotnet / dotnet/efcore

Add an analyzer for new objects in OnConfiguring that are used as part of the ServiceProvider key

Open
#27,856 0 comments 1 reaction 0 assignees View on GitHub
area-analyzer
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

For example, correct configuration:
```C#
o.HttpClientFactory(this.SomeFlag ? () => new HttpClient() : () => StaticClient)
```

Incorrect configuration that will result in a different ServiceProvider key for each context instance:

```C#
o.HttpClientFactory(() => this.SomeFlag ? new HttpClient() : StaticClient)
```

This also applies to `WebProxy`, `UseMemoryCache`, `DefaultAzureCredential` and the new model interceptor.

However, this isn't an issue if the specified lifetime for options is `Singleton`

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.