Tuesday, December 8, 2009

Obtics

If you're working with .NET and any sort of observability, such as WPF bindings, you owe it to yourself to check out Obtics. It's an excellent library that turns an expression into an observable expression. It has full support for System.Linq.Enumerable methods and for arbitary expressions.

Using Obtics and a custom helper method, you can do things like:

public int AplusB
{
    get
    {
        return Getter(() => AplusB, () =>
            A + B
        );
     }
}

Now, whenever A or B change, a property changed notification is fired for AplusB.

Imagine now that the expression inside is not as simple as A + B but several lines of code involving collections, linq extension methods, and more. Obtics is able to automatically add observability to the entire complex expression.

Need to watch for changes to proerties in collections? Obtics has elegant ways of doing that too. It's a great library, very much worth checking out. In comparison to CLINQ or Bindable LINQ, Obtics has a focus on full expression support. Having full expression support is extremely powerful and Obtics seems to be an excellent implementation of it.

Friday, December 4, 2009

Pleasant Solutions



Starting a software company has definitely been one of the most challenging and enlightening experiences in my life. Owning a business takes a great deal of commitment and will to persevere. I am a partner at Pleasant Solutions, a custom software development house. We have a fantastic team and it's a joy to come to work every day and collaborate with these excellent individuals.

Specializing in custom software development is a difficult road on which to tread.  Although we are able to produce high quality tailored solutions for our clients, doing so profitably is a major challenge.  Thankfully, having excellent people allows us to adapt quickly to a broad range of tasks.  Developing certain infrastructure components has been very beneficial to us.  For example, we have a hiring system that allows us to screen our applicants in a more accurate and efficient way than reading resumes.  As another example, we significantly enhanced the open source ActiveWriter (with minor contributions to Castle.ActiveRecord and NHibernate along the way) to meet our needs.  In fact, we have continued to make improvements to our in-house tool to the degree that our developers need little knowledge of the nitty gritty of NHibernate in order to complete even complex business and data modelling tasks.  Building knowledge and experience into a tool has been very beneficial for us.  When we do our next project, we can bring along our past experience automatically, increasing quality and reducing costs.

We're still learning and exploring all the time, and we hope to continue to share our talent and passion for software development for years to come.

WPF and NHibernate Lazy Proxies

Using NHibernate proxies with WPF binding will likely leave you scratching your head at moments. There are at least two issues that can get in your way.

The first of these is that objects with INotifyPropertyChanged implementations will not update when the property is changed. Even though the event is fired, the WPF value never updates itself. This is because WPF compares the source of the event against the object that it originally registered the event with. Since the source of the event is the actual implementation object hidden by the proxy, but the object WPF knows about is the proxy object, WPF ignores the event. The best way to fix this is to have the proxy object rewrite the property changed events. There is a detailed explanation and a simple implementation here, but be aware that it doesn't redirect events from the source but throws its own events when properties are set.

The other issue you will sometimes run into is a strange null reference exception when setting the value of a dependency property. There is a bug in WPF where it doesn't properly handle the names of classes without any namespaces. Since the lazy proxy objects have no namespace, this bug pops up. The issue is fixed in WPFv4, but if you aren't able to upgrade, you can fix this by changing a line in Castle.DynamicProxy.

In ClassProxyGenerator.GenerateCode, add the "Proxies." part to the following line:

String newName = "Proxies." + targetType.Name + "Proxy" + Guid.NewGuid().ToString("N");

This should help anyone experiencing the error relating to DetermineWhetherDBNullIsValid.