我们需要将第三方SOAP api与我们的系统集成。由于我们是SaaS解决方案提供商,我们需要支持所有版本的第三方。 我们的配置是客户A的版本为1.8,客户B的版本为2.0。 (新版本的版本可能需要数月。)
我正在寻找的是创建可以与所有版本一起使用的库的一般策略。
作为一种解决方案,我认为在单个C#库中创建多个命名空间版本。
我想要所有实体的包装类,而不管版本如何。所以我将调用该包装类,它将使用所需的版本初始化对象。
我该怎么做?这是处理这种情况的正确方法吗?
如果需要任何进一步的信息,请告诉我们!
谢谢!
Ankur Kalavadia
答案 0 :(得分:2)
您可以使用以下解决方案来解决您的问题,这对您的实施有所帮助。
- >首先,您创建了一个公共接口,它可以用于所有相同类型的公共标识符
- >按版本名称
创建单独的名称空间 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
- >为所有版本创建相同的类名(例如,版本v1中的class1,class2,使用不同实现的v2)
- >创建以下常用函数以生成相关对象
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;
}
}
- >调用功能如下
iTestInterface obj = GetEntity(classnameString);
- >调用相关对象方法。以上电话会对所有相关课程都是通用的。
谢谢&问候 Shailesh Chopra