Sunday, May 28, 2017

wpf, prism, inotifydataerrorinfo and fluent validation

Time for a technical post. Recently my team began work on a new product and the architecture that was selected was WPF, Prism with Unity. Yea I know ..... but we went with WPF because of the intensiveness of the graphics we need to use. The design patterns we choose was Prism with Unity and MVVM. The following samples were taken from efforts to collect data needed to create a connection string for a Maria DB.



As we began looking at a validation implementation, we looked at Fluent Validation. After tinkering around, it seemed very well like by the community and seemed like a great way to manage validation rules.

We started constructing our base class. We created our own ValidatableBindableBase class which which inherits from Prism's BindableBase and INotifyDataErrorInfo. With the INotifyDataErrorInfo, we're implementing the interface with a dictionary, adding and removing items to the dictionary when the DataErrorsChangedEventArgs fires.

So this is the model in which our classes will be built upon. Nothing special, just defining our properties in our model. Notice the model also inherits from our base class - ValidatableBindableBase.

Using Fluent Validation, we created our validation rules based on our model. Fluent Validation makes it incredibly easy to construct rulesets using lambda expressions. Just pass in the entity type to the AbstractValidator base class.


Here I'm showing the view (a partial view of our view) which demonstrates the controls. We are using DevExpress controls here. The controls bind to the viewmodel properties and uses the ValidatesOnNotifyDataErrors attribute set to True. Now the control subscribes to the error raised in the changed DataErrorsChangedEventArgs.

Lastly, the viewmodel. During the construction of the viewmodel, the Save delegate is registered. When the user clicks the save button, the validation is fired. What a joy it was to see the validation fields light up.


It took a little while to get it constructed just right, but I really like this implementation.

Sunday, May 14, 2017

rain barrel 2.0

This year I was ready to begin my rain barrels 2.0. My goal is to have full pressure spray from my rain barrels, powered by solar. Well .... let's start by cleaning them up. 


I pulled them from under the deck (where they are stored for the winter) and cleaned them out really good.



I got them for $45 from my local water treatment plan several years ago. They work great, except the pressure is not enough to get water through them. I ended up using water pails to move water to my garden. Not much fun or efficient.



I didn't use them last year and of course, no rain most of the summer. Not jinxing this summer, bring them out.


I went off to the nearest big box store and purchased about 3 of these.


Couple of coats and a few days later .... all done.


Next, I purchased a highly recommended water pump from Amazon. It is the cutest, little portable guy. It is electric .... so this year, I'll plug it in. Next year though ...... solar power!



We plugged in the hose and turned on the pump. And TA-DA, pull pressure!


Nice solid pressure directly from the rain barrels.


Now ... I have the coolest rain barrels that provide full pressure to a garden hose. Look out garden, full organic rain water - all for you.