0

I'm currently trying to find a way to map from one object to another where the first one is a domain model and the other one is an object that represents the same thing, but for a completely different use. A simple example:

public class SnmpDeviceService {

    private readonly Dictionary<int, 3rdPartyLibObj> devices;
    private SnmpLibrary snmp;

    public SnmpDeviceService() {
        snmp = new SnmpLibrary();
        snmp.ObjOnlineEvent += DeviceOnlineEvent;
    }

    public void Add(MyDevice device) {
        3rdPartyLibObj libObj = new 3rdPartyLibObj(device.IpAddress);
        devices.Add(device.Id, libObj);
        snmp.Observe(libObj);
    }

    public void DeviceOnlineEvent(object sender, args) {
        // Question here!
    }

Question

I've now received libObj (that is not mine) back with additional information. I would like to invoke a domain event now, but another service that listens for a certain domain event doesn't know the type 3rdPartyLibObj, he only knows MyDevice. How can I now map from 3rdPartyLibObj to MyDevice if they represent the same thing but look different? And if I want to keep MyDevice during the time I wait for the DeviceOnlineEvent, how should I reference it in my dictionary to keep MyDevice and 3rdPartyLibObj in context?

Like this?:

public Dictionary<int id, Tuple<MyDevice, 3rdPartyLibObj>>();
4

1 回答 1

0

如果LibObj不是你的,为什么你在你的上下文中使用它?

如果我误解了你的问题,请告诉我......在你的上下文中(定义明确的有界上下文?)你用于这些东西的对象是 MyDevice 并且3rdPartyLibObj来自不同的上下文(那么不同的上下文如何通信?你认为上下文映射或其他东西像那样 ?)。如果准确,我建议您限制3rdPartyLibObj在您的上下文中使用(使用反腐败层?)。

于 2014-03-07T11:05:18.150 回答