I’m writing a C# .NET module and I would like to use the provider pattern.
If my code is running on a web server, I have access to System.Web.Configuration and can call ProvidersHelper to load an appropriate provider as determined by the web.config data.
If my code is running in a stand-alone environment, I won’t have access to this class.
It seems to me that I might write a wrapper class that uses reflection to (a) determine if I can get to the built in System.Web.Configuration.ProvidersHelper, and if not, (b) provide a functionally equivalent interface that would rely only on the resources I have available in the stand-alone mode.
Has anyone out there come across this issue before and/or have suggestions?
If you want to avoid the reference on the
System.Webassembly, you’ll have to create an interface which exposes the information you’re interested in and get your consumers to provide implementors of this interface as appropriate:This pattern is called Dependency Injection and Inversion of Control.