public static AddressViewModel Create(IAddressObject o) { switch (o) { case WebAddressObject web: return(create(web)); case EmailAddressObject email: return(create(email)); case TelecomAddressObject device: return(create(device)); } return(create(o as GeographicAddressObject)); }
public async Task AddObject(IAddressObject o) { if (o is WebAddressObject web) { dbSet.Add(web.DbRecord); } if (o is EmailAddressObject email) { dbSet.Add(email.DbRecord); } if (o is GeographicAddressObject adr) { dbSet.Add(adr.DbRecord); } if (o is TelecomAddressObject tel) { dbSet.Add(tel.DbRecord); } await db.SaveChangesAsync(); }
//4-Service Locator public Company() { this._address = ServiceLocator.getAddress(); } //Static Class Service Locator is used to search for objects
//3-Interface Implementation public void setAddress(IAddressObject obj) { _address = obj; }
/*Applying Dependency Injection in 4 ways*/ //1-Contructor public Company(IAddressObject obj) { _address = obj; }