现有的WCF服务的xml转换,需要与MEF集成吗?
我的应用程序是在WCF中的xml转换。现在需要更改以与 MEF 集成。哪种是实现 MEF 的最佳方式,或者我应该使用哪种类型的架构来以更少的工作量和更少的现有代码更改来实现?
编辑
说明:
我有四个酒店的xml改造 在wcf服务中。一端是固定的 格式xml和另一端不同 每个新酒店的 xml 格式。 另有20家酒店工作即将到来。为了 我需要一些重复的工作 可重用和可扩展的架构。 我想转换现有的 使用 MEF 进行架构升级 未来的视角。所以我可以做得更好 用于接下来的 20 个酒店 xml 转换。
My application is in WCF of xml transformation. now need to change to integrate with MEF. which is the best way to implement MEF or which type of architecture should i use to implement with less effort and less change in existing code?
EDIT
Explanation:
I have four hotel xml transformation
in wcf service. At one end it is fixed
format xml and another end different
xml format for each new hotel.and
another 20 hotel work will come. for
this repetative work i need some
re-usable and extendable architecture.
i want to convert existing
architecture upgrade with MEF for
future perspective. so i can do better
for next 20 hotel xml transformation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 Xml 转换进展如何?是通过代码还是 XSLT?
如果通过代码,我会定义一个
IXmlTranslator
来将您的 xml 转换为通用模型:其中 XmlModel 是您的通用模型:
您需要具体知道要使用哪个翻译器,因此您需要传递某种元数据,因此我们将定义一个名称:
因此示例翻译器可能如下所示:
MEF 将负责将元数据投影到 INamedMetadata 的实例中。接下来,创建一个使用 IXmlTranslator 的服务:
我已将可用翻译器的枚举作为构造函数参数的一部分,因为它定义了服务工作所需的依赖项。 MEF 将负责在组合时注入此枚举。
您需要做的是将
XmlTranslatorService
的实例导入
到您想要使用它的任何类中,或者您可以直接从您的初始化一个实例CompositionContainer
,例如:剩下的唯一一件事就是
XmlModel
模型类。XmlModel
类序列化到目标 xml 中。希望这能为您指明正确的方向?
How are you doing your Xml transformation? Is it through code, or XSLT?
If through code, I would define an
IXmlTranslator
that converts your xml into a common model:Where XmlModel is your common model:
You'd need to specifically know which translator to use, so you'd need to pass in some sort of metadata, so we'll define a name:
So an example translator could look like:
MEF will take care of projecting your metadata into an instance of INamedMetadata. Next, create a service which consumes
IXmlTranslator
s:I've made the enumerable of available translators part of the constructor arguments, as it defines dependencies that are required for the service to work. MEF will take care of injecting this enumerable at composition time.
What you need to do, is either
Import
an instance of theXmlTranslatorService
into whatever class you want to use it from, or you can initialise an instance directly from yourCompositionContainer
, e.g.:The only thing remaining would be
XmlModel
model class.XmlModel
class into the target xml.Hope that points you in the right direction?