kentico12 form component DI implementation

innovix solutions asked on August 9, 2019 13:27

Hi All,

We had a custom drop-down component for widget and seems we cannot apply DI. Any suggestion on this?

You can check below code. One argument Constructor is not working.

public CustomDropDownComponent(ICustomDropdownComponentRepository _repo) { this.repo = _repo ?? new CustomDropDownComponentRepository(); }

public class CustomDropDownComponent : SelectorFormComponent<CustomDropDownProperties>
{
    private ICustomDropdownComponentRepository repo; 



    public CustomDropDownComponent()
    {
    }
  // below constructor is not working
   public CustomDropDownComponent(ICustomDropdownComponentRepository _repo)
    {

       this.repo = _repo ?? new CustomDropDownComponentRepository();
    }

   protected override IEnumerable<SelectListItem> GetItems()
    {

        objList = repo.GetSelectItems();
        foreach (var item in objList)
        {

            var listItem = new SelectListItem()
            {
                Value = item.Value,
                Text = item.Key
            };

            yield return listItem;
        }

    }

}

}

   Please, sign in to be able to submit a new answer.