google-ads-dotnet icon indicating copy to clipboard operation
google-ads-dotnet copied to clipboard

Configure using the options pattern

Open jeffdahl opened this issue 2 years ago • 6 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();

jeffdahl avatar Jan 17 '23 16:01 jeffdahl

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?

AnashOommen avatar Jan 18 '23 04:01 AnashOommen

Good to know. Instead of singletons, we could register GoogleAdsConfig and GoogleAdsClient as transient. Would that fit the design better?

On Tue, Jan 17, 2023 at 8:31 PM Anash P. Oommen @.***> wrote:

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 https://github.com/Raibaz wdyt?

— Reply to this email directly, view it on GitHub https://github.com/googleads/google-ads-dotnet/issues/483#issuecomment-1386472553, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVHMB5ZDFOM237YZK35UV3WS5W2HANCNFSM6AAAAAAT6C42BY . You are receiving this because you authored the thread.Message ID: @.***>

jeffdahl avatar Jan 18 '23 05:01 jeffdahl

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.

Raibaz avatar Jan 24 '23 10:01 Raibaz

@jeffdahl I think @Raibaz and I need some more time thinking through this. How about we accept this bug for ourselves, and send you a PR when we are ready? I'd be happy to credit you for the work even if we end up with a different implementation.

AnashOommen avatar Feb 07 '23 16:02 AnashOommen

Sure, sounds good. Thanks for considering my suggestion.

Jeff

On Tue, Feb 7, 2023, 8:58 AM Anash P. Oommen @.***> wrote:

@jeffdahl https://github.com/jeffdahl I think @Raibaz https://github.com/Raibaz and I need some more time thinking through this. How about we accept this bug for ourselves, and send you a PR when we are ready? I'd be happy to credit you for the work even if we end up with a different implementation.

— Reply to this email directly, view it on GitHub https://github.com/googleads/google-ads-dotnet/issues/483#issuecomment-1421105343, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABVHMBYOVM4BLVEHCLDVBC3WWJ5LZANCNFSM6AAAAAAT6C42BY . You are receiving this because you were mentioned.Message ID: @.***>

jeffdahl avatar Feb 07 '23 19:02 jeffdahl

Any consideration of adding the two interfaces in PR #540? As explained in the PR, adding these two interfaces will allow a configured IGoogleAdsClient to be injected via the DI container.

Thanks for considering.

jeffdahl avatar Nov 14 '23 06:11 jeffdahl