This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var schoolInstance = new School(); | |
var oxford = new OxfordUniversity(); | |
//Inject dependency as method parameter | |
schoolInstance.AttendClass("Kenneth", oxford); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class School | |
{ | |
public string AttendClass(string student, ISchool school) | |
{ | |
return school.Learn(student); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var schoolInstance = new School(); | |
schoolInstance.AttendClass("Anthony"); | |
var oxford = new OxfordUniversity(); | |
//Injecting the dependency via a property, which is the School Property | |
schoolInstance.school = oxford; | |
schoolInstance.AttendClass("Kenneth"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class School | |
{ | |
private ISchool _school; | |
public ISchool school | |
{ | |
get | |
{ | |
if (_school == null) school = new HavardUniversity(); | |
return _school; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
School havard = new School(new HavardUniversity()); | |
School oxford = new School(new OxfordUniversity()); | |
var havardStudent = havard.AttendClass("Anthony"); | |
var oxfordStudent = oxford.AttendClass("Kenneth"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HavardUniversity : ISchool | |
{ | |
public string Learn(string student) | |
{ | |
return string.Format($"My name is {student}, and I attend Havard"); | |
} | |
} | |
public class OxfordUniversity : ISchool | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISchool | |
{ | |
public string Learn(string student); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class School | |
{ | |
private readonly ISchool _school; | |
public School(ISchool school) | |
{ | |
this._school = school; | |
} | |
public string AttendClass(string student) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
WebResponse response = await request.GetResponseAsync(); | |
using (StreamReader reader = new StreamReader(response.GetResponseStream())) | |
{ | |
string responseContent = reader.ReadToEnd(); | |
JObject adResponse = | |
Newtonsoft.Json.JsonConvert.DeserializeObject<JObject>(responseContent); | |
return adResponse; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
byte[] data = Encoding.UTF8.GetBytes(content); | |
WebRequest request = WebRequest.Create(url); | |
request.Method = "POST"; | |
request.ContentType = "application/json"; | |
request.Headers.Add("Authorization", "Bearer " + token); | |
request.ContentLength = data.Length; |
NewerOlder