Andrey
Andrey

Reputation: 21285

Using ObservableCollection in ASP.NET

I need to use functionality that ObservableCollection provides, in my asp.net app. My only concern is that this class is a part of WindowsBase assembly and I'm not sure if it's a good idea to include a windows assembly in a web project.

Any ideas/comments?

Thanks!

Upvotes: 3

Views: 5349

Answers (1)

Robert Harvey
Robert Harvey

Reputation: 180808

If you have a creative use for ObservableCollection outside of WPF, I don't see any reason you should not take advantage of it. Even Microsoft says:

Before implementing your own collection, consider using ObservableCollection<T> or one of the existing collection classes, such as List<T>, Collection<T>, and BindingList<T>, among many others.

This article has an example of an ObservableCollection in WPF. However, the author makes this statement at the end of the article:

Although this application made use of the binding support provided by the ObservableCollection class and also reacted to its CollectionChanged event in order to update the user interface, you needn't use the class this way. Because it notifies listeners that its contents have changed, you can replace any List or Collection instance that you use with an ObservableCollection instance (even if you're not creating a WPF application) and then hook up event handlers to notify clients that the collection's contents have changed.

Upvotes: 5

Related Questions