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>>();