Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Options binding from configuration should not have conditionally compiled code #35

Closed
divega opened this issue Feb 25, 2015 · 14 comments
Closed
Assignees

Comments

@divega
Copy link

divega commented Feb 25, 2015

Update: Covert.ChangeType() is now available in System.Runtime.Extensions and we can remove the conditional compilation.

Currently the whole body of OptionsServices.ReadProperties(object, IConfiguration) is in an #if and won't do anything if the functionality of Convert.ChangeType() presumably isn't available in the target platform. I believe we should decide more explicitly what we want to do with this, e.g.:

  1. Throw an exception
  2. Make sure the needed functionality is made available in CoreCLR and use it
@Eilon
Copy link
Member

Eilon commented Feb 26, 2015

I think @yishaigalatzer wanted to kill that whole type conversion feature for now and just do strings.

Do we have any components that truly rely on the type conversion behavior of Options / config? Does EF make use of it?

@divega
Copy link
Author

divega commented Mar 2, 2015

Updating title because Covert.ChangeType() is now available in System.Runtime.Extensions and we can remove the ifdefs.

@divega
Copy link
Author

divega commented Mar 2, 2015

@Eilon in general our Options classes are optimized for code configuration and they are not just for pulling settings from configuration, so not sure it is a good idea to kill the type conversion/binding. Was there any scenario in which it was dangerous or didn't work?

@divega divega changed the title Options binding from config silently no-ops if Convert isn't available Options binding from configuration should not have conditionally compiled code Mar 2, 2015
@Eilon
Copy link
Member

Eilon commented Mar 3, 2015

For code-based config you don't need type conversion right?

I think the only danger in the current state of the code is that it ignores stuff instead of either working or at least failing. I'm fine if we can do more basic conversions successfully, but then we should fail if we can't. That's probably a decent compromise and easy to implement, right?

@divega
Copy link
Author

divega commented Mar 3, 2015

Yep, we should not swallow exceptions from Covert.ChangType(). Frameworks that need more complex conversions/parsing should implement their own logic. @HaoK sure has more context on why the empty catch ended there.

On the other hand is by design that we skip properties not specified on configuration.

@Eilon
Copy link
Member

Eilon commented Mar 3, 2015

Skipping missing values is certainly fine (if I understood correctly). I mean ultimately we'll add new options and wouldn't expect "old" configs to start to fail.

@HaoK
Copy link
Member

HaoK commented Mar 3, 2015

I can take a look at this again, it was added very early on and since nothing was really using it, I didn't flesh the type conversion logic out much at all

@HaoK HaoK self-assigned this Mar 3, 2015
@yishaigalatzer
Copy link

My key feedback here was that the data should start with some well known subkey otherwise random collisions will start happenning

@Eilon
Copy link
Member

Eilon commented Mar 3, 2015

The user passes in an optional sub-key when they use config, no?

@HaoK
Copy link
Member

HaoK commented Mar 3, 2015

Yeah the caller is responsible for selecting the right parent config for the options to bind against, i.e.

services.ConfigureMvc(config.GetSubKey("mvc"))

@Eilon
Copy link
Member

Eilon commented Mar 3, 2015

Yeah I think that's fine by me. Forcing a parent key was discussed a long time ago and was determined to be far too difficult to use. If we had a default we'd need a way to un-set it, we'd need a way to document it, we'd still have collisions (though rare), and we'd still have to support custom sub-keys anyway.

@lodejard
Copy link

lodejard commented Mar 3, 2015

Tangent - I wonder if GetSubKey should be GetKey?

@yishaigalatzer
Copy link

The fact that you pass configuration rather than something like key or configuration node, confused me I want even aware of the pattern. From the shape of the API it looks like you just pass the configuration object proper. Consider making it more obvious, such that the API is self explanatory

@HaoK
Copy link
Member

HaoK commented Mar 4, 2015 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants