views:

141

answers:

1

Hey guys

Just wondering how how people handle Authorization when using MVVM and/or View Models.

If I wasn't using VM's I would be passing back the Model and it would have a property which I could check if a user can edit a given object/property but when using MVVM I am disconnecting myself from the business object... and thus doen't know what the security should be any more.

Is this a case where the mapper should be aware of the Authorization that is in place and don't copy across the data if the Authorization check fails. If this was the case I am guessing that the mapper would have to see some properties on the VM to let the interface know which fields are missing data because of the Authorization failure.

If this does occur within the mapper, how does this fit in with things like AutoMapper, etc.

Cheers Anthony

+1  A: 

The ViewModel can expose this property from the Model to your View. That's the purpose of the ViewModel in MVVM.

Instead of directly attaching to your Model (which is what you specified you'd do without MVVM), you can just expose this through your VM, and attach to the VM.

Reed Copsey
So are you saying that my VM would internally store the BO and publicly expose an Authorization property which is actually just a proxy wrapper for an Authorization property on the BO?
vdh_ant
Pretty much... It's frequent that VM's just expose Model properties for the View layer. That's a very common task of the VM layer.
Reed Copsey
Do you know of any good resources that go into the patterns and practices in more depth in regards to VM's and MVVM?
vdh_ant
You can read my series on the subject - It goes into this in quite a bit of depth, starting from standard events-based programming, and transitioning to MVVM and why it works: http://reedcopsey.com/2010/01/07/better-user-and-developer-experiences-from-windows-forms-to-wpf-with-mvvm/
Reed Copsey