-
Notifications
You must be signed in to change notification settings - Fork 442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MailPace Sender #379
base: master
Are you sure you want to change the base?
Add MailPace Sender #379
Conversation
this FluentEmailServicesBuilder builder, | ||
string serverToken) | ||
{ | ||
builder.Services.TryAdd(ServiceDescriptor.Scoped<ISender>(_ => new MailPaceSender(serverToken))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the reason to not bind this in Singleton scope? If there are a large number of concurrent requests couldn't you get resource exhaustion due to all the HttpClients that are created in MailPaceSender's constructor?
Microsoft indicates either HttpClient should be created in singleton scope or use IHttpClientFactory. https://learn.microsoft.com/en-us/dotnet/fundamentals/networking/http/httpclient-guidelines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right! Singleton makes more sense here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The one caveat with singleton on this class is not being able to set the PooledConnectionLifetime on the internal HttpClient itself. Binding in Singleton scope would help with resource exhaustion but there could be a potential issue with long lived connections. Changes to DNS records may not be picked up. It might be better to manage the HttpClient lifecycle inside MailGunSender and MailPaceSender and set the PooledConnectionLifetime to some reasonable default. Then it won't matter how ISender is bound.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would passing in IHttpClientFactory
be a better option? Let the DI container handle HttpClient
lifetimes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think that should work too.
I had a play around with this for MailGunSender in #382
Fixes #377