ASP.NET Best Practices?
elibroftw opened this issue · comments
Is it better to create a new postmark client for each controller, or should we be using a Singleton or something like that and create only one client?
For reference, Microsoft tutorials for MongoDB creates a service for a collection and uses that service/singleton to insert/get.
// Program.cs
builder.Services.AddSingleton(new PostmarkClient(builder.Configuration["PostmarkServerToken"]));
// MyController.cs
public MyController(PostmarkClient postmarkClient) {
// Initialize Postmark client
_postmarkClient = postmarkClient;
}
Postmark-dotnet internally uses a static instance of HttpClient
that is shared by all postmark clients - you can use either approach.