Solved

How to implement different address validation providers in .NET?

Posted on 2011-02-16
8
406 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

744 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

14 Experts available now in Live!

Get 1:1 Help Now