Search code examples
c#datagridviewbindinglistbusiness-logic-layerservice-layer

Should you return a BindingList from a business layer (or service layer, domain model, etc.)?


I need a BindingList in my UI to provide two-way databinding between my collection and a DataGridView. However, it doesn't seem correct to return a BindingList from your business layer (or domain layer, service layer, data layer, etc.). That is, I'd only be using a BindingList because of a UI requirement, and now this UI need would be coupled with my domain layer.

What is the "proper" decoupled way to do this? Should I be returning an IList and then copying it into a BindingList for presentation purposes? From a real world perspective, is this overhead worth anything?


Solution

  • I think that the domain layer would return the more generic types and whether they be notifying (ObservableCollection<>) or not (IEnumerable<> or IList<>) is up to the requirements.

    The UI layer can deal with tranforming them as they wish (or not) into IBindingList if they need that functionality.

    We have used BindableLinq to great success to achieve the goals of notifying/synchronised binding list's (possibly with filters) at the UI layer.