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<IDropdownListEntity> GetDropdownList()
{
CountryStore store = new CountryStore();
return store.SimpleSortedListByName<DropdownListEntity>();
}
}
public class CityController : ApiController
{
//Returns the list of cities
public IEnumerable<IDropdownListEntity> SortedListForDropdown()
{
CityStore store = new CityStore();
return store.SimpleSortedListByName<DropdownListEntity>();
}
}