Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to implement different address validation providers in .NET?

Posted on 2011-02-16
8
Medium Priority
?
423 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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:
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

610 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