jeudi 22 octobre 2020

Azure functions design guide lines

I have a model class structured as shown below in my azure function.

public class BaseContact
{
public string FirstName { get; set; }
public string LastName { get; set; }
}

public class Contact : BaseContact
{
public string Email{ get; set; }
}

My azure function some times receives JSON that contains only BaseContact details, some times I might receive full Contact as well (along with email).

public void UpdateContact(BaseContact contact)
{
    // This would never gives me Email if Email is also passed in the JSON input
}

public void UpdateContact(Contact contact)
{
    // This would fail if I have to parse the JSON as BaseContact model and pass it here.
}

In my UpdateContact method, If I have to update the full details to a SQL database and if I use Contact as input parameter that would fail if I send BaseContact. If I use Basecontact as input method then I will not get Email.

How should I solve this problem ?

Aucun commentaire:

Enregistrer un commentaire