Template WebAPI: Defining External Configurations
A part of the Template WebAPI series.
One design constraint that I wanted to enforce on the application is that the idea of app settings should stay in the within the API layer. But we still need a mechanism for transferring configurations form the API down to the various implementations.
The best design I’ve come across is to define your configuration dependencies through interfaces, which you can type against your configuration file.
Take a look at MongoConnector.cs, where we have to give it a connection string and database name in order to instantiate it. We wrap the configuration in the file MongoConfig.
Then when we want to setup the service, we can define the configuration by referring to our app settings.
Now we have define a configuration for an external service, without having to pass around our complete AppSettings file, and the configuration is abstracted away from the external services.
Full configuration can be found on Github.
Originally published at jameslouiecs.blogspot.com.