ChrisMissal / Formo

Formo allows you to use your configuration file as a dynamic object. Turn your web.config or application settings into a rich, dynamic object.
http://chrismissal.com/Formo/
MIT License
259 stars 33 forks source link

Set up null behaviour #36

Closed onliner10 closed 9 years ago

onliner10 commented 9 years ago

Added flag ThrowIfNull in configuration class, which would throw exception if a value with given key does not exist (instead of returning null)

ChrisMissal commented 9 years ago

Hey @onliner10, thanks for the PR.

One opinion of Formo is that it shouldn't fail when a variable isn't found. I definitely like the fact that this is a switch that can be turned on/off, but my recommendation would be to move that up a level into a configuration wrapper.

It's best not to call Formo.Configuration directly, but to capture the variables needed into another object. I would recommend moving the exception to this layer. If you'd like, I can provide an example of that, just let me know if that's something you'd like to see in the docs/wiki/blog.

onliner10 commented 9 years ago

@ChrisMissal , thanks for your feedback!

I believe it's due to Fail Fast, to throw an exception if value doesn't exist but somebody expects it to be there. If we return null, instead, it could possibly cause error propagation in production systems.

Besides, I think, in many cases we wouldn't like to add another level of abstraction and the flag could be useful, e.g. in project I am currently working with.