Solved

How to implement different address validation providers in .NET?

Posted on 2011-02-16
8
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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…
The viewer will learn how to count occurrences of each item in an array.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

717 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