0

Is there an easy way to compose an object based on other objects? i am thinking the solution lies using DI container & Interfaces eg.

public IObjectA : IObjectB, IObjectC {...}

public ObjectA CreateObjectA()
{
 ObjectB b = new ObjectB();
 ObjectC c = new ObjectC();
 return container.GetExportedValues<IObjectA>(b,c);
}

The whole idea is not to write any mapping code to create an object.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • 1
    THe question is a bit unclear. Just to confirm, can you specify which language you are talking about? Typically Objects are instantiations of a class so you can't really make an object based on other objects. If your intent was regarding classes, you can derive a new class based on an existing class and add functionality to it or you can create a new class that contains members that are objects of a different type. – R Schultz Nov 24 '14 at 00:38
  • The language is c#, what i mean is something like Instantiate, Cloning the objects, then return a new object. i think i can write a generic method to do it but wondering if it was already done. Thanks – Joseph Bartholomew Nov 24 '14 at 02:23
  • Did you try Automapper? – abatishchev Nov 24 '14 at 05:01
  • Thanks, i will use ValueInjecter. answered this but it was deleted – Joseph Bartholomew Nov 24 '14 at 13:14

0 Answers0