How do you load IStatePersistenceService

Topics: CAB & Smart Client Software Factory
Aug 23, 2006 at 7:13 AM
originally posted by: MikeColls

I am calling Load() from my root work item and I get the following exception. Do I need to load the IStatePersistenceService and if so how would I load it?

Service Microsoft.Practices.CompositeUI.Services.IStatePersistenceService, required for component .ABCWorkItem is not available in the current context.
Aug 23, 2006 at 7:30 AM
originally posted by: JKraft4PIT

Yeah you have to either add your own service, but a couple come with CAB.

But a good thing to do is have this code inside your workitem that uses the PersistenceService.

Public ReadOnly Property PersistenceService() As IStatePersistenceService
Return Services.Get(Of IStatePersistenceService)()
End Get
End Property

Public Sub ShowInfoDetail(ByVal DetailID As long)

'get ID for details window, so only create info detail once
Dim idKey As String = String.Format("Detail#{0}", DetailID)

Dim detailWorkItem As DetailWorkItem = Me.Items.Get(Of InfoDetailWorkItem)(idKey)

If detailWorkItem Is Nothing Then

detailWorkItem = WorkItems.AddNew(Of InfoDetailWorkItem)(idKey)

detailWorkItem.ID = idKey

If PersistenceService IsNot Nothing AndAlso PersistenceService.Contains(detailWorkItem.ID) Then
End If

End If

'Now you have a detailWorkitem either a new one, or one with it's state filled. Either way do what you will with it.

End Sub

'I got this code form a example that CAB has. I like using it since if I save my workitems state this will try to load it.

As you can see I use it for showing a detailWorkitem. It works really well.

It will retreive the workitem if it is already loaded.
If it isn't then it will create one.
If there is persitant Storage it will use it and look for my workitems saved state and load it.

The point of the code is to show you how to use persisant storage on a workitem. (PS in the workitem when closing it you should call the so it saves the workitem to your persitent stroage). In the help it will show you how to start the persitent storage.