Rockford Lhotka

 Monday, November 2, 2009

When I sit down to work on CSLA .NET I look at the wish list, and I tend to order my work based on a few priorities:

  1. Is it a bug with no workaround?
  2. Will it help a Magenic client/project?
  3. Is it fun/interesting/intellectually stimulating to me?
  4. Will it help make the lives of a reasonable number of users better?
  5. Is it easy (low-hanging fruit)?
  6. Does it make CSLA more "complete"? (like the recent MVVM work)

And there are some anti-priorities:

  1. Is it boring? Or worse, boring and time consuming?
  2. Does it increase complexity without amazing payoff in productivity/flexibility?
  3. Does it increase my testing/support surface area?
  4. Does it focus on "legacy" technologies (now including Windows Forms, Remoting, asmx, Enterprise Services and maybe Web Forms)?
  5. Does it solve a problem that's already been solved? (like ORM stuff or UI framework stuff)

These priorities are especially important during point releases, but they certainly factor into major releases (like 4.0) as well. Though the "fun factor" becomes a much bigger priority for major releases, and tactical things like bug fixes or specific Magenic client requirements are usually not as big an issue.

I guess this is one advantage of working on a free framework. Since I’m not directly making money by selling the framework, I can prioritize what I do based on my own intellectual stimulation and fun as much as anything else.

Monday, November 2, 2009 10:25:17 AM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Friday, October 30, 2009

CSLA .NET 3.8.0 Beta 3 is now available for download

Beta 3 includes fixes for some bugs found in Beta 2 (mostly in ViewModelBase and BusyAnimation), and two more significant changes:

  • InvokeMethod no longer attempts to manage the attached UI control’s IsEnabled property; this is a breaking change, but was necessary to avoid an otherwise unavoidable memory leak. It wasn’t a good practice anyway, so this implementation is both safer and better.
  • There’s a new Csla.Web.Mvc.CslaModelBinder class; it addresses a key issue around the data annotation validation attributes and how their validation information is reported back to the ASP.NET MVC framework. (I know I said Beta 1 was feature-complete, but this was too important to hold back…)

I’ve also continued to update samples, and I think all the C# samples are now updated, as are some of the VB ones. Hopefully I can get the rest of the VB ones updated before final release.

I am still on track to release 3.8.0 in about a week – hopefully Nov 6 or 9.

Friday, October 30, 2009 5:07:05 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Thursday, October 29, 2009

I’m not too sure about all this “manifesto” stuff these days. Certain right-wing politicians from days gone by are surely rolling in their graves. Then again, today’s highly communist/socialist oriented open source worldview would have gotten many of us into a lot of trouble just a few decades ago…

Regardless, there’s now the SOA Manifesto. And it seems to capture the spirit of SOA in a concise manner.

In fact, its opening statement, talking about putting business value above technology and so forth, seems to make sense for any software endeavor, not just ones that are service-oriented.

If you consider that SOA is much more of an enterprise architecture than it is an application architecture, this all makes a great deal of sense. The idea that applications should use service-oriented communication when they need to interact with each other is exactly the sweet spot for service-orientation.

In that context, saying things like external uniformity and internal diversity are good is clearly correct; because different applications may require different technologies or implementation choices, but they all need to work with some enterprise-standardized message-based service model.

I still suspect SOA may ultimately make a big difference in our industry. But I also think it will take decades to do so, just like object-orientation. People were working on object-orientation for well over 20 years before the ideas became mainstream. SOA is (if you are really generous) maybe a decade old, so it is probably time to work on some formalism so it is ready to become mainstream 10-15 years from now :)

Thursday, October 29, 2009 10:23:13 AM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Sunday, October 25, 2009

I have put CSLA .NET 3.8.0 Beta 2 online for download.

This completes the work for version 3.8.0, and (barring anyone finding a show-stopping issue) I plan to release 3.8 in just a couple weeks.

For Windows Forms and Web Forms users there are not any major new features, but some of the bug fixes may be valuable. Upgrading from 3.7 to 3.8 should be painless for these UI types (as well as XML services and workflow interfaces).

If you use WPF or Silverlight, you will almost certainly want to take a look at the features in 3.8. The downside is that there are several breaking changes in the XAML controls, but the upside is that the new XAML control implementations are far superior to previous versions. Controls impacted include:

  • PropertyStatus – now supports a “pull model” so a UI control can bind to properties of PropertyStatus, rather than having PropertyStatus directly manipulate the UI control’s IsReadOnly and IsEnabled properties. Also in Silverlight, PropertyStatus now makes use of the Silverlight 3 binding capabilities.
  • InvokeMethod – can now be triggered by any UI event, and can invoke a couple different method signatures on the DataContext. Also, MethodParameter is now bindable. The end result is that InvokeMethod provides really good support for both the CslaDataProvider model and the MVVM design pattern.
  • Execute – a new control that is a trigger action that works in the Blend 3 Interactivity model. This is very similar to InvokeMethod, but works with the Blend 3 scheme.
  • ViewModelBase<T> – provides a base class to make it easy to build a viewmodel class when using the MVVM pattern.
  • ViewModel<T> – provides a base class to make it easy to build a viewmodel class that works with InvokeMethod/Execute when using the MVVM pattern.
  • CslaDataProvider – the ObjectInstance property is now bindable, so it is possible to create master-detail (parent-child) relationships in the UI between different data provider controls.

See this blog post for more MVVM information.

Other important or interesting features include:

  • Support for System.ComponentModel.DataAnnotations validation attributes.
  • Performance enhancements for MobileFormatter, including the use of binary XML.
  • Better support for altering the behavior of IsDirty when using managed backing fields.

There are also numerous bug fixes, including (hopefully) a solution to the memory leak issue with BusyAnimation. See the change logs for more details about bug fixes.

Sunday, October 25, 2009 10:37:49 PM (Central Standard Time, UTC-06:00)  #    Disclaimer

I’ve blogged about MVVM several times over the past few months. If you watch my posts you’ll see that I started out pretty skeptical of the pattern, and then worked through it trying to find the shiny silver lining that was promised.

One of the biggest challenges with patterns is that people expect them to be a recipe, when in reality they are just a vague formalization of a concept. Just look at MVC, an incredibly mature pattern, and all the radically different ways it gets implemented (for better or often worse) in applications. While MVVM isn’t nearly as mature as MVC, it turns out that it really is a good concept – when “applied correctly”.

In my view a pattern should only be used if its positive consequences outweigh its negative consequences. Many patterns, oddly enough, require extra code and/or configuration over what you’d normally write – which is a negative consequence. And in some interpretations of MVVM this is very much the case – which was the primary reason for my initial skepticism.

On the other hand, with some thought, foresight and work it is often possible to mitigate some of the more negative consequences of many of the more popular patterns. This turns out to be absolutely true for MVVM.

To me, the real sweet spot for a pattern is if it can provide its positive consequences with little or no negative impact at all.

My time with CSLA .NET 3.8 has been divided into just a few areas:

  • Bug fixes (minor)
  • DataAnnotations (minor – but really nice)
  • Silverlight 3 element binding (major – also really nice)
  • MVVM support (major – and very cool)

In the end, I think I’ve got something that enables the use of the MVVM design pattern, probably in several variations, to work swimmingly with CSLA .NET. I’ll go so far as to say that I think this implementation of MVVM makes developing Silverlight and WPF apps easier than out-of-the-box coding (drag-and-drop, handling UI events, using data provider controls). And by easier I mean no more code, often less code, and easier to read/test/maintain code. So the pattern is purely helpful, with no negative consequences of note. Exactly what you’d hope for.

What does this look like?

CSLA .NET MVVM Support

First, you must realize that CSLA .NET helps you create what’s called a rich model as opposed to various other technologies (like Add Service Reference) that help you create an anemic model. Using MVVM with an anemic model is useful, but can require a lot of work, because your viewmodel object needs to compensate for all the stuff the model doesn’t do. But with a rich model, the viewmodel requires far less work because the model is already first-class citizen.

To this end, CSLA .NET provides some helper types that you may optionally use to enable a rich model MVVM implementation. At the same time, I fully recognize that many (most?) people will find/build and use an MVVM UI framework, so the CSLA .NET helper types can be used individually, all together or not at all – as you choose.

Two parts of MVVM already (mostly) exist if you are using CSLA .NET and Silverlight or WPF. CSLA .NET helps you create business domain objects that are your Model, and XAML helps you create your View (with a little help). So in my mind those are essentially a given. What’s left is the need to create the ViewModel.

Notice that I said XAML gives you the view – with a little help. This is because WPF commanding isn’t quite enough to do MVVM, and Silverlight doesn’t even have commanding. So the “little help” is something that handles arbitrary UI events and transforms them into arbitrary method calls on the DataContext (presumably your viewmodel). I would expect any decent MVVM UI framework to solve this most basic problem, and of course they do. Sadly there’s no standard solution, so each UI framework does their own thing.

View Event Handling

While not a UI framework, CSLA .NET does provide a basic solution to this one critical problem with using XAML to create a view. In fact it provides two solutions: InvokeMethod and Execute.

InvokeMethod is an attached property that understands how to handle an arbitrary UI event and to call an arbitrary method on the DataContext when that event is raised. As an attached property, you can attach it to any UIElement (FrameworkElement in Silverlight) to handle any event to call any method on the DataContext. Here’s a simple example:

<Button Content=”Save”
            csla:InvokeMethod.TriggerEvent=”Click”
            csla:InvokeMethod.MethodName=”SaveData” />

Execute is similar, but relies on the Blend 3 System.Windows.Interactivity event trigger concept to detect that the event was raised:

<Button Content="Save">
  <i:Interaction.Triggers>
    <i:EventTrigger EventName="Click">
      <csla:Execute MethodName="SaveData" />
    </i:EventTrigger>
  </i:Interaction.Triggers>
</Button>

The advantage of using InvokeMethod is that it has several options around data binding that simply aren’t available to a trigger action like Execute. Most notably, InvokeMethod has a MethodParameter property that can be bound using a binding expression – so it can pull values from other UI controls, resources, the DataContext, etc. There’s no way to do this with a trigger action like Execute.

The advantage of using Execute is that trigger actions are something the Blend 3 designer understands. So InvokeMethod pretty much requires typing XAML, while Execute integrates more naturally into the Blend design experience.

In either case, the method on your viewmodel looks like this:

public void SaveData()
{
}

Or this:

public void SaveData(object sender, ExecuteEventArgs e)
{
}

Either one is fine, as InvokeMethod and Execute will work with either method signature. If you use the second option, the args parameter contains information about the control the raises the event, the event’s args and an optional MethodParameter value.

Creating a ViewModel

When using a rich model, I believe that a good viewmodel object will expose the model as a property, so the View can bind directly against the Model and still have access to the viewmodel. This way the viewmodel can extend and enhance the model without any extra effort. This works particularly well if the model already understands data binding – which is one of the primary features of CSLA .NET.

CSLA .NET includes ViewModelBase<T> and ViewModel<T>, both of which are base classes designed to make it easy to build a viewmodel for a CSLA .NET business object.

ViewModelBase has a public Model property, a handful of other useful public properties (like CanSave), and a whole bunch of protected methods. Again, my assumption is that many people will use some MVVM UI framework, and that framework will have its own constraints on how public methods must be implemented for their particular “commanding equivalent” functionality. The ViewModelBase class allows you to create public methods matching your UI framework’s requirements, but you can usually just delegate those calls to existing protected methods that do most of the work. These methods include:

DoRefresh

(WPF only) Synchronously invokes a static factory method to create/fetch the Model.

BeginRefresh

Asynchronously invokes a static factory method to create/fetch the Model.

DoSave

(WPF only) Synchronously saves the Model (if it is a root object).

BeginSave

Asynchronously saves the Model (if it is a root object).

AddItem

Adds an item to the collection (if the Model is a BusinessListBase).

Remove

Removes an item from the collection (if the Model is a BusinessListBase).

Delete

Marks the Model for deletion (if the Model is a root BusinessBase).

Cancel

Cancels any changes that have been made to the Model (if ManageObjectLifetime is true).

ViewModel is a subclass of ViewModelBase that implements public methods for use by InvokeMethod and/or Execute. If you use InvokeMethod/Execute, then you’ll want to create your viewmodel objects by subclassing ViewModel:

public class CustomerViewModel : ViewModel<Customer>
{
  public CustomerViewModel()
  {
    BeginRefresh(“NewCustomer”);
  }
}

In many cases the constructor is all you’ll need to write, since the ViewModel<T> base class already implements the methods necessary to build a standard data entry form.

Again, if you are using an MVVM UI framework, you’ll probably want to create your own base class, somewhat like ViewModel<T>, by subclassing ViewModelBase<T> and implementing your public methods to match the requirements of the UI framework. You can use the code in ViewModel<T> as an example of how to do this.

I should also point out that the Model property is bindable. This means you can create “child viewmodel” objects that get their Model value by being bound to the property of some “parent viewmodel” or parent model. For example, you might have a form for working with SalesOrder objects, so your top level viewmodel exposes a SalesOrder object through its Model property. The following would be the XAML to set up the viewmodel for the form:

<UserControl.Resources>
  <this:SalesOrderViewModel x:Key="ViewModel" />
</UserControl.Resources>
<Grid Name=”LayoutRoot” DataContext=”{Binding Source={StaticResource ViewModel}}”>

Now you could just bind the detail region of the form (where you show the line items) to the LineItems property of the business object, and that works fine.

But suppose you want to bind a button or hyperlink control to an AddItem() method so the user can add items to the LineItems collection. How do you do that without writing code? The answer is that you set up a viewmodel (probably LineItemsViewModel) for that child region of the form, and you have the Model property of LineItemsViewModel bound to the LineItems property of the SalesOrder business object. In the child region you’d do something like this:

<Grid Name=”ChildRegionContainer”>
  <Grid.Resources>
    <this:LineItemsViewModel x:Key=”LineItemsViewModel”
                                           Model=”{Binding Path=Model.LineItems}”/>
  </Grid.Resources>
  <Grid Name=”ChildRegion” DataContext=”{Binding Source={StaticResource LineItemsViewModel}}”>

The advantage of this is that any controls inside the ChildRegion grid can invoke methods on LineItemsViewModel – such as AddItem() or Remove() to add and remove items from the collection – all with no coding on your part.

Creating the Model

This is the part where I just smile. Because you already have the model if you used CSLA .NET and good object-oriented design to build your business domain objects. The same business objects you may already be using for Windows Forms or Web Forms will almost certainly just work in your WPF or Silverlight application (assuming you are using CSLA .NET 3.5 or higher – and can upgrade to CSLA .NET 3.8).

The primary goal of CSLA .NET, first and foremost, is to enable you to create a business layer that encapsulates your business, validation and authorization logic into a set of business domain objects. By doing so, you end up with a formal business layer on top of which you can build Silverlight, WPF, ASP.NET MVC, Web Forms, Windows Forms, asmx service or WCF service interfaces.

So the whole point of having this business layer is that when something like XAML comes along all you need to worry about is how to rebuild the UI, possibly using MVVM. But you don’t need to worry about rebuilding the business layer, or the data access layer or the database.

I’m pretty happy with the way CSLA .NET 3.8 enables the MVVM design pattern in Silverlight and WPF. As I said to start with, you’d hope that a pattern gives you positive consequences with little or no downside. With the support of InvokeMethod, Execute, ViewModelBase and ViewModel I think CSLA .NET makes MVVM meet that goal. And in fact, I think it allows you to build a UI with less code than many, seemingly simpler, alternatives.

Sunday, October 25, 2009 10:23:04 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Thursday, October 22, 2009

I was just complaining that the cool new Windows 7 features weren’t available to me as a .NET developer – at least not without painful p/invoke calls.

My complaints were ill-founded however, as it turns out there’s a solution in the form of the Windows API Code Pack.

This makes me happy (though I haven’t tried it yet, so I’m just assuming it works) because I want access to Jump Lists and some other Windows shell integration concepts – which appear to be nicely included in the code pack.

Thursday, October 22, 2009 10:56:24 AM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Wednesday, October 21, 2009

If you didn’t know, I’m an uber-geek in a family of uber-geeks, and that (of course) includes Star Trek, as well as supporting and being involved in the local fan community.

My wife is the fight choreographer for this play (and setting up fights with a batleth is really fun!). And the show itself is very good; good acting, well written script and a nice mix of action and comedy. It is a novel twist on an old story :)

About the Klingon Christmas Carol:

Scrooge has no honor, nor any courage. Can three ghosts help him to become the true warrior he ought to be in time to save Tiny Tim from a horrible fate? Performed in the Original Klingon with English Supertitles, and narrative analysis from The Vulcan Institute of Cultural Anthropology.

The Dickens classic tale of ghosts and redemption adapted to reflect the Warrior Code of Honor and then translated into tlhIngan Hol  (That's the Klingon Language).

A co-production of Commedia Beauregard and the IKV RakeHell of the Klingon Assault Group.

If you are in the upper-midwest region, I suggest you attend a show and see (according to the Klingons) the original Christmas Carol story.

Wednesday, October 21, 2009 9:20:36 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Tuesday, October 20, 2009

Dunn Training is offering their CSLA Master Class next month in Atlanta

http://www.dunntraining.com/training/cslamasterclass.htm

If you want to get up to speed fast with CSLA .NET this is the class for you. Instructor Miguel Castro is a CSLA .NET expert and has contributed elements to the framework itself, as well as being the author of the courseware used for the class.

Sign up now!

Tuesday, October 20, 2009 1:28:14 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Monday, October 19, 2009

Microsoft has made Visual Studio 2010 and .NET 4.0 Beta 2 available for download to MSDN subscribers, with general availability soon. VS10 includes a lot of really nice features over VS2008, and I’m personally very excited to see the Beta 2 release.

I’ve made a pre-alpha CSLA .NET “4.0” available for download as well. This is really just the version 3.8.0 code (somewhere between beta 1 and beta 2) that I’ve updated to build under Visual Studio 2010 with .NET 4.0.

Over the next few months I’ll continue to release updates to version 4.0 that take advantage of the .NET 4.0 features, but I wanted to make sure there was a version online that builds with VS10 as soon as possible, so this is it – enjoy!

Monday, October 19, 2009 1:41:33 PM (Central Standard Time, UTC-06:00)  #    Disclaimer
 Tuesday, October 13, 2009

A lot of organizations rely on Gartner for valuable advice. Personally though, I remember a point in the mid-90’s where Gartner pronounced that Unix would be the dominant operating system long before 2009. Of course actual Unix is a total non-issue, having destroyed itself through fragmentation. Linux is still very meaningful, but that wasn’t what Gartner was talking about…

So when Gartner speaks, people listen – but if people are smart they’ll take what’s said with a big pile of salt.

Gartner apparently just came out with some thoughts on Windows 7. Mary Jo Foley has a summary.

And some of what they say rings true. Businesses really are more conservative than consumers about adopting new operating systems. So when Gartner talks about the lack of adoption and slow movement at the corporate level I tend to agree.

But Windows 7 really is a different release from what we’ve seen in many years. The caution expressed around maturity of the product, and shifting to 64 bit deployments is, I think, misplaced.

I can honestly say that I’ve never seen Windows be so smooth, and provide such comprehensive driver support before official launch. Remember, it doesn’t really come out until later this month, but Windows 7 64 bit is already more compatible with my computer than Vista.

Sure, an enterprise does need to run through a testing period, especially if they are upgrading from Windows 2000 or XP. There are changes, as you’d expect given that Win2k and XP are nearly a decade old. But 99.9% of the changes in Win7 are for the better – making the user’s life better, and the network/system admin’s life better.

My recommendation however, is for organizations and individuals to be aggressive in moving to Windows 7. This is because the transition is the smoothest I’ve seen in nearly 20 years of working with Windows, and the user productivity and sheer enjoyment are the highest I’ve seen since Windows 98SE.

(disclaimer: I don’t own Microsoft stock, so my recommendation here is based purely on my personal enthusiasm for Windows 7 and how much more fun my computers have been since I upgraded)

Tuesday, October 13, 2009 11:07:10 AM (Central Standard Time, UTC-06:00)  #    Disclaimer