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>>();
Acrotygma
  • 2,531
  • 3
  • 27
  • 54
  • Instead of saving a tuple it would be better to create an object that wraps MyDevice and your 3rdPartyLibObj class. I don't know the capabilities of 3rdPartyLibObj, but I would prefer any events to be triggered directly on this wrapper object and be dispatched further to any other observers from there as a domain event. – Lodewijk Bogaards Mar 07 '14 at 09:13

1 Answers1

0

If LibObj is not your, why you use it in your context ?

Tell me if I misunderstood your problem... In your context (bounded context well defined ?) the object that you use for this stuff is MyDevice and 3rdPartyLibObj comes from different context (so how different context communicate ? Do you thought with Context Map or something like that ?). If it is exact, I recommand you to limit the use of 3rdPartyLibObj in your context (using an anticorruption layer ?).

rad
  • 1,857
  • 1
  • 20
  • 30