建立插件类,继承AbstractListPlugIn,在插件中调用自己写的service,需要传递this.Context,而使用T service = _mapServer.GetService
问题是为什么ServerUrl会为null?
我自定义工厂已经继承ServiceFactory。
代码如下:
///
/// 应用服务器服务组件创建工厂
///
public class CustomerServiceFactory: ServiceFactory
{
///
/// 服务接口-实现类 映射关系
///
public static new ServicesContainer _mapServer = new ServicesContainer();
static CustomerServiceFactory()
{
RegisterService();
}
static bool notRegistered = true;
///
/// 获取指定接口实现类实例
///
///
///
///
public static new T GetService
{
if (ctx == null)
{
throw new Exception("{ctx == null}");
}
return GetService
}
///
/// 在App层 通过该方法访问服务;请通过kingdee.bos.app.servicehelper访问
///
///
///
///
static T GetService
{
if (ctx == null)
{
throw new Exception("{ctx == null}");
}
return GetService
}
static T GetService
{
if (notRegistered)
{
RegisterService();
}
var instance = _mapServer.GetService
if (instance == null)
throw new KDException("???", "instance==null");
return instance;
}
///
/// 注册服务
///
public static new void RegisterService()
{
if (notRegistered)
{
_mapServer.Add(typeof(ICustomService).AssemblyQualifiedName, "CTC.DataSyncTask.ICustomService,CTC.DataSyncTask");
notRegistered = false;
}
}
public static ICustomService GetCustomService(Context ctx)
{
return GetService
}
///
/// 销毁服务类实例
///
///
public static new void CloseService(Object service)
{
IDisposable disposable = service as IDisposable;
if (disposable != null)
{
disposable.Dispose();
}
}
}
推荐阅读