Skip to content
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

Provide a AdWordsAppConfig constructor that works with IConfigurationSection #191

Closed
aevitas opened this issue Nov 3, 2018 · 3 comments
Closed
Assignees
Labels
enhancement New feature or request P2 usability This issue is related to a usability issue with the client library.

Comments

@aevitas
Copy link

aevitas commented Nov 3, 2018

This is more of a design issue than an actual functional issue, but in my opinion, it's a fairly significant design mistake that should be corrected. I am using this library with ASP.NET Core 2.1 specifically.

Tl;dr - it should accept a IConfigurationSection instead

Currently, AdWordsAppConfig has two public ctors:

   public AdWordsAppConfig();
   public AdWordsAppConfig(IConfigurationRoot configurationRoot);

The first constructor is a bit of a magic constructor. It does stuff by reading from a config section, but it's not very apparent where it's getting its values from, and it fails without a meaningful exception message.

The second constructor accepts an IConfigurationRoot. In ASP.NET Core's Startup.cs file, configuration is already mostly handled for us, and we'll only have an IConfiguration instance. We can cast this to an IConfigurationRoot and pass it to the AdWordsAppConfig, but that's less than ideal.

Passing the configuration root eventually hits ReadSettings. This method doesn't handle "surplus" values in the configuration very well, and instead of ignoring them, it'll throw a NullReferenceException. This means that we can not have anything in our config file except the AdWords credentials, or it'll throw.

This could fairly easily be fixed by either adding an overload which accepts IConfigurationSection, so we can pass Configuration.GetSection("AdWordsCredentials"); or similar. Personally however, I think the current overload accepting the configuration root is strictly wrong from a conceptual perspective and should not exist.

As it stands, the only way I've gotten it to work in ASP.NET Core is by creating a separate configuration file and registering the resulting IConfigurationRoot with the DI container:

    var builder = new ConfigurationBuilder();
    builder.AddJsonFile("adwordssettings.json");

    var config = builder.Build();

    services.AddSingleton(config);

Which works, but in my opinion is far from ideal.

Looking forward to your thoughts on this, and thank you very much for the great work you guys have done to make this library!

@christopherseeley christopherseeley self-assigned this Nov 8, 2018
@christopherseeley
Copy link
Member

This seems reasonable, I'll take a look. Thanks for all the context and details!

@christopherseeley christopherseeley added the enhancement New feature or request label Nov 13, 2018
@AnashOommen AnashOommen added the P2 label Dec 18, 2018
@AnashOommen
Copy link
Member

I'll add an extra constructor that looks like

public AdWordsAppConfig(IConfigurationSection configurationSection);

that does what you requested.

@AnashOommen AnashOommen added the usability This issue is related to a usability issue with the client library. label Dec 18, 2018
@AnashOommen AnashOommen changed the title AdWordsAppConfig should not accept IConfigurationRoot as an argument Provide a AdWordsAppConfig constructor that works with IConfigurationSection Dec 18, 2018
@AnashOommen
Copy link
Member

Fixed in 24.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P2 usability This issue is related to a usability issue with the client library.
Projects
None yet
Development

No branches or pull requests

3 participants