I only know how to Register
and Resolve
new instances. However, I am not sure how to pass existing objects as parameters in to an instance I want to resolve.
Q1:
interface IPerson {
person FindAnOtherPerson();
void MakeFriends();
}
class Person : IPerson {
private List<Person> _people;
//...
void MakeFriends() {
var peter = FindAnOtherPerson(); //from _people
var rel = new Relationship(this, peter); //build a relationship
//how to pass params? something like Resolve<IRelationship>(this, peter)?
}
//...
}
Q2:
interface IParent { }
interface IChild { }
class Parent : IParent {
private IChild _child;
public Parent() {
_child = new Child(this); //parent knows child
//With DI, how do I resolve child and pass 'this' to child?
}
}
class Child : IChild {
private IParent _parent;
public Child(IParent p) { //child knows parent
_parent = p;
}
}
I thought about this for awhile but not enough brain juice to work it out. Please help thanks :)