This is the first in a series of real world dynamic data examples.
Lets’s assume I have a data which is exposed via a service.
public interface IPersonService { IObservableCache<Person, PersonKey> Cache { get; } }
and I want to bind the data to a screen. In dynamic data it is done like this.
//this is a simple extension of observable collection which comes as part of the package var collection = new ObservableCollectionExtended<Person>(); //Dynamic data is an extension of reactive so subscribe at the end of the chain var loader = personService.Cache.Connect() .Sort(SortExpressionComparer<Person>.Ascending(p=>p.FirstName).ThenByAscending(p=>p.LastName)) .ObserveOnDispatcher() .Bind(collection) .Subscribe();
The binding will always reflect the data in the cache (and in the stated sort order). That was easy so let’s extend this so we can apply a filter. This is also easy.
var loader = personService.Cache.Connect().Filter(p=>p.Age>50)
or use a filter controller which allows the filter to be changed any time.
//create a filter controller var filterController = new FilterController<Person>(); //filter can be changed any time by applying the following method filterController.Change(p=>p.Age>50); var loader = personService.Cache.Connect().Filter(filterController)
And that is that. We can filter, sort and bind changeable data with very little code.
Thanks for sharing your thoughts on site. Regards
LikeLike
Please don’t use var, when it is so importand to understand what the real return type is when a method like Connect() is called
LikeLike
Thanks for sharing this but I don’t understand where can we find this FilterController that you’re using here, it’s not in any of the GitHub repos. You used it in several blog posts and it looks real interesting, I think it makes Filter method much more versatile but I must be missing something as the full source is nowhere to be found. Either way, thank you for your contributions!
LikeLike
Filter controller was removed a few years ago. It was replaced with an overload of Filter which accepts an observable predicate. The examples in dynamic trade have been updated to use the newer methodology.
LikeLike