In this post I talked about building out a configuration service that could be split into various areas of concerns so that each piece can be injected where it makes sense (without all of the noise of the rest of the configuration).
Previously, the registration looked like this:
Reflection
With reflection, we can loop through the properties of our configuration service and make it so you don’t need to do the additional step of registration if and when you add another configuration interface to your configuration service.
First, get the properties off of the interface. FIelds are different than Properties… Properties are things with getters and setters (I always have to look this up)
Then we loop through those properties and call the same builder like before. We still resolve the IConfigurationService, but this time we pass that to the .GetValue function of the property. This will return an object representing the property on the provided instance, which, in this case, is our ConfigurationService.
Finally, just register the property type. This tells AutoFac that you want that type to be associated with whatever concrete implementation returned in the previous step.