How to implement different address validation providers in .NET?
Posted on 2011-02-16
I want to be able to use different postal address validation providers for my .NET application, and want to know the best and/or easiest way.
The interface would be quite simple - probably pass in some address object to a "Verify" method and have the code check the address and modify it in some way if necessary, then perhaps pass a boolean to indicate if any modifications were made.
My problem is, I would like supporting a new address provider to not require re-supplying the original application, or not having the original source code. So it should be easy for the existing validation assembly to be replaced by another one. Perhaps have the config file (app.config or web.config) specify the assembly to use for address validation.
In COM this would be pretty simple - just have the string for the ProgId specified somewhere, then do a CreateObject(progridname) to load the code. The implementation would just have to implement some standard interface to be "swappable" - so the VB COM code would be something like:
Dim addressVerify as IAddressVerify
Dim progidname as String
progidname = ReadProviderProgId()
Set addressVerify = CreateObject(progidname)
isModified = addressVerify.Verify(myaddress)
I'm guessing something like this should be achievable with serialization or perhaps some other way - can anyone advise?
I'll be implementing this in ASP.NET but I'm assuming that shouldn't really affect the solution.
Also I am working with .NET 3.5.