Configure using the options pattern
jeffdahl opened this issue · comments
The options pattern simplifies configuration. When using a settings.json
file, instead of configuring GoogleAds with the following three lines:
IConfigurationSection section = Configuration.GetSection("GoogleAdsApi");
GoogleAdsConfig config = new GoogleAdsConfig(section);
GoogleAdsClient client = new GoogleAdsClient(config);
configuration can be done in a single line:
using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices((hostContext, services) =>
services.AddGoogleAdsClient(hostContext.Configuration))
.Build();
None of GoogleAdsConfig, GoogleAdsClient and services are designed to be singletons, because that's not how the product works in the general case.
I'll give it some thought, but perhaps it is simpler to have a SingletonGoogleAdsClientProvider helper class specifically for this use case. @Raibaz wdyt?
Not entirely sure if registering GoogleAdsConfig and GoogleAdsClient as transient would be feasible; I'd rather keep them as they are and instead add a Singleton to wrap them for dependency injection usage.