Solved

How to implement different address validation providers in .NET?

Posted on 2011-02-16
8
412 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:purplesoup
  • 4
8 Comments
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 34908603
There is no any validator for Postal address. You have to write your own code (In client side/ or server side)
to validate postal address.

For more info: please see below URL:


http://stackoverflow.com/questions/758450/mailing-address-verification-etc-get-county-from-zip

Let me know for any question.
0
 

Author Comment

by:purplesoup
ID: 34926303
I haven't explained myself well. I'm not looking for some postal address software - there are many options for that - I'm looking for a design that will allow me to implement different providers and allow the application at run-time to plug in a new provider.
0
 

Author Comment

by:purplesoup
ID: 34927221
Oh - I meant to say "this should be achievable with reflection", not "this should be achievable with serialization" above  - sorry.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:purplesoup
ID: 34927486
Well I've just written a little test using reflection - this is a simple calculator, but the principle is the same I guess - any comments on whether this is a good way to go or if there is a better alternative?


int i = int.Parse(textBox1.Text);
                int j = int.Parse(textBox2.Text);

                // load assembly
                Assembly calAssembly = Assembly.LoadFile(Properties.Settings.Default.AssumblyFilePath);
                Type calType = calAssembly.GetType(Properties.Settings.Default.CalculatorType);
                ICalculator calculator = Activator.CreateInstance(calType) as ICalculator;

                if (calculator != null)
                {
                    textBox3.Text = calculator.Add(i, j).ToString();    
                }

Open in new window

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 34957729
There are plenty of resources available to help with this problem, with sounds like a job for plug-ins.  It looks like you have found something to give you a leg up--interfaces.

Introduction to Building a Plug-In Architecture Using C#
http://www.c-sharpcorner.com/uploadfile/rmcochran/plug_in_architecture09092007111353am/plug_in_architecture.aspx

As long as you implement your plug-in interface, you can easily define those in separate assemblies that you can change out with configuration files.  Another place to look is to Inversion of Control (or Dependency Injection).

Inversion of control
http://www.devx.com/Java/Article/27583
0
 

Author Closing Comment

by:purplesoup
ID: 34996102
The plug-in link is basically the same code I suggested but has a few more bells and whistles.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where did System.Data.Objects go? 2 23
Problem!!! 8 33
DataTables + iCheck + pagination Issue 2 15
VB.NET 2008 - SQL Timeout 9 23
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now