Controller class pattern The GetDropdownList() function is being called on a couple of controllers based on this example and it may be called in many other controllers, so this code is being repeated. I was thinking of encapsulating this portion of code to the base class and call that base class in these controllers, but I got stuck and don't know how to implement it. Can you please show me a way using SOLID principles?

public interface IDropdownListEntity
{
    string Value { get; set; }
    string Text { get; set; }
}

public sealed class DropdownListEntity: IDropdownListEntity
{
    public string Value { get; set; }
    public string Text { get; set; }
}

public class CountryController : ApiController
{
    //Returns the list of countries
    public IEnumerable&lt;IDropdownListEntity&gt; GetDropdownList()
    {
        CountryStore store = new CountryStore();

        return store.SimpleSortedListByName&lt;DropdownListEntity&gt;();
    }
}

public class CityController : ApiController
{
    //Returns the list of cities
    public IEnumerable&lt;IDropdownListEntity&gt; SortedListForDropdown()
    {
        CityStore store = new CityStore();

        return store.SimpleSortedListByName&lt;DropdownListEntity&gt;();
    }
}
Web API should not be bound to a particular UI

API calls should not bound to a user interface requirement, so that it could be used in multiple places without any addition requirement. In the above code, it is returning a list of dropdownlist values rather than a list of entities.  

Your controller code may look like this:

public class ConstantsController : ApiController
{
    private readonly IConstantRepository _constantRepository;

    public ConstantsController(IConstantRepository constantRepository)
    {
        _constantRepository = constantRepository;
    }


    [Route("Constants/City")]
    [HttpGet]
    public IEnumerable&lt;City&gt; GetCity()
    {
        return _constantRepository.GetCity();
    }


    [Route("Constants/Country")]
    [HttpGet]
    public IEnumerable&lt;Country&gt; Country()
    {
        return _constantRepository.GetCountry();
    }
}


Note: I am using Web API 2 for this code.

This code can be used by any kind of application like this:


  http://yoururl/Constants/Country

Use a DI container to inject dependencies into your controller

Use Unity or a simple injector to inject dependencies. It will help you to isolate components.

public interface IConstantRepository
{
    IEnumerable&lt;City&gt; GetCity();

    IEnumerable&lt;Country&gt; GetCountry();
}



Also, include unit tests in your applications.