public void Notify(/*string message,*/ ISon selectedSon) //method dependency injection { if (selectedSon /*Son*/ == null) { Console.WriteLine("Dad needs help"); } //son.Help(message); //selectedSon.Help(message); //Son.Help(message); }
[Test] public void CanCreateProxy() { var all = new Dictionary <MemberInfo, int>(); var type = typeof(ISon); var i = type.GetInterfaces(); foreach (var parent in i) { GetMemembers(parent, all); } GetMemembers(type, all); ISon mock = MockRepository.GenerateStub <ISon>(); var son = NotifyPropertyChangeFactory.GetProxy(mock); mock.Name = "Son"; mock.Stub(m => m.Job).Return("NoJob"); Assert.That(son.Name, Is.EqualTo(mock.Name)); Assert.That(son.Age, Is.EqualTo(10)); Assert.That(son.Job, Is.EqualTo("NoJob")); Assert.That(((IFather)son).Job, Is.EqualTo("NoJob")); Assert.That(((IMother)son).Job, Is.EqualTo("NoJob")); Factory.SaveAssembly(); }
//Constructor //1. Example of constructor injection //Dad is injecting what son he wants to call in the constructor //public Dad(ISon selectedSon) //{ // son = selectedSon; //} //2. Example of method injection public void Notify(ISon selectedSon, string message) { selectedSon.Help(message); }
public Dad(ISon selectedSon) //ctor dependency injection { son = selectedSon; }
public static void Notify(ISon son, string message) { son.Help(message); }
public Dad(ISon selectedSon) { _son = selectedSon; }
public string NotifySon(ISon Cson, string Message) { return(Cson.Help(Message)); }
public string GetHelp(ISon Cson, string Message) { return(Cson.Help(Message)); }
public Dad(ISon SelectedSon) { son = SelectedSon; }