Interface and Databinding question

Interface and Databinding question

Old forum URL: forums.lhotka.net/forums/t/590.aspx


ajj3085 posted on Tuesday, July 11, 2006

Hi all,

I have an interface which defines a specialized list.  The interface is in a 'common' business layer assembly.

The idea is that I have a Contacts business assembly, and would like to use composition in my Quoting business assembly, but don't want to the Quoting assembly to the Contacts assembly.  The UI layer will reference both assemblies.  This makes sense to me, but if anyone has comments on this setup, please post.  Now, my main question..

The interface is defined as such:  public interface IPhoneList<T> where T : IPhoneInfo { }.

This works fine so far.  I have an IContact interface as well, defined like so:

public interface IContact {
        IPhoneList<IPhoneInfo> PhoneNumbers{ get; }
}

Now, when I bind to IContact, and then try to bind a BindingSource to PhoneNumbers, PhoneNumbers doesn't appear in the list of properties.  I suspect this is because IPhoneList<T> doesn't implement any kind of collection interface.  So the question is, which interface should IPhoneList also implement?  I'm thinking System.Collections.Genetic.IList<T>, as that seems the most basic list type, and should already be implemented by my business collections (since they inherit BindingList, which I believe implements IList). 

What are your suggestions?
thanks
Andy

ajj3085 replied on Tuesday, July 11, 2006

Some more info..

In the Add Project Data Source wizard, I noticed some interfaces show up, and others don't.  What would make an interface NOT appear on this list?  This is very frustrating about databinding, which is otherwise very useful.

Andy

RockfordLhotka replied on Tuesday, July 11, 2006

I was under the impression that data binding didn't support interfaces at all - at least not for binding discrete properties/columns.

ajj3085 replied on Wednesday, July 12, 2006

I have an interface, IContact, and I can use the Add Data Source wizard to add an object datasource based on the interface.  In a form, I can create a BindingSource using that datasource.  If i set controls datasources on that form to the BindingSource, I can pick which properties the controls are bound to.. so it seems to work.

But for some reasons, The Add Data Source wizard just don't list some interfaces.  Odder still, the PhoneNumbers property does show if I bind one bindingsource to another... its just not showing up to be able to create a project datasource by itself.

Andy

vargasbo replied on Wednesday, July 12, 2006

Yes, I do belive DataSource was not designed to support interfaces However, you could hack it to make it work, but is it really worth it? Nope.

ajj3085 replied on Wednesday, July 12, 2006

It seems that it doesn't support generic interfaces, just standard ones.  But you're right, trying to get it to work off the interface is more effort than its worth; the only reason I went that was was because object I'm getting is actually declared as the interface..

RockfordLhotka replied on Wednesday, July 12, 2006

One goal behind the binding source is to enable data source flexibility. As long as your runtime data source has the same shape (properties/columns) as what was defined at design time, you can use it.
 
What this means is that you should (in theory anyway) be able to build your form against a concrete business class that has only the common properties for all objects - a concrete implementation of your interface. At runtime then, you can set the DataSource property to any object that has (at a minimum) those properties. Extra properties are ignored, but missing properties cause an exception.
 
The point being, that perhaps you don't need to use the interface for data binding, because all your objects will have those properties anyway.
 
Rocky


From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, July 12, 2006 1:15 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Interface and Databinding question

It seems that it doesn't support generic interfaces, just standard ones.  But you're right, trying to get it to work off the interface is more effort than its worth; the only reason I went that was was because object I'm getting is actually declared as the interface..



ajj3085 replied on Wednesday, July 12, 2006

Yes, that makes sense.  I forget that databinding doesn't 'tightly' couple anything.

Thanks for the feedback.

Copyright (c) Marimer LLC