We need to integrate third party SOAP api with our system. As we are SaaS solution provider, we need to support all version of third party. We have configuration that Customer A has version 1.8, Customer B has version 2.0. (Version may took months for new version.)
What I am looking for is a general strategy for creating a library that can work with all versions.
As a solution I think to create multiple namespace version wise in single C# library.
I want wrapper class for all entity irrespective of version. so i will call that wrapper class and it will initialize object with required version.
How can i do that ? Is it right way to handle a situation like this?
If any further information is needed, let me know!
Thanks!
Ankur Kalavadia
you can use following solution for your problem which help to you in your implementation.
--> First you create common interface which can be usefull for common identifier of all the same types
--> Make Seperate NameSpace by version name
DefaultNameSpace : ABC.XYZ
Version : 1.6.2
Then make the namespace patterns as
e.g. ABC.XYZ.V162 (Replcing . and set prefix as per classname norms (always start with Alphabet ) )
Create Class under above namespace with implementing interface
--> Create same classname for all the versions ( e.g. class1 , class2 common in version v1, v2 with diferent implementation )
--> Create below common function to generate relevant object
public static iTestInterface GetEntity(string className)
{
string versionPrefix = "v_";
string strVersion = 1.6.2;
string dllPath =System.Web.HttpRuntime.BinDirectory;
string dllName = "dllName.dll";
string Version = versionPrefix +
string strclassNameWithFullPath = dllPath + Version.Replace(".", "") + "." + className;
try
{
string strAssemblyWithPath = string.Concat(dllPath, dllName);
if (!System.IO.File.Exists(strAssemblyWithPath))
{
return null;
}
System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(strAssemblyWithPath);
Type t = assembly.GetType(strclassNameWithFullPath);
object obj = Activator.CreateInstance(t);
return (iTestInterface)obj;
}
catch (Exception exc)
{
//string errStr = string.Format("Error occured while late assembly binding. dllPath = {0}, dllName = {1}, className = {2}.", dllPath, dllName, className);
return null;
}
}
--> Call function as below
iTestInterface obj = GetEntity(classnameString);
--> call relevent object methods. Above call will be common for all relevant classes.
Thanks & Regards Shailesh Chopra