Topics: CAB & Smart Client Software Factory
Jun 28, 2007 at 11:18 AM
To begin with, let me say I'm new at Composite UI, so if I ask anything that seems dumb, Sorry, I guess I am when it comes to this. I've created a application where I have a workItem (login control: main.dll) that uses a service (UserService:common.dll)
In my LoginController class:
I reference Common.dll, I've included it in the Profile Catalog as well:

Private _useService As UserService = nothing
<ServiceDependency()> _
Public WriteOnly Property UserService() as UserService
Set (byval value as UserService)
_useService = value
End Property

In the UserService class:
I reference the CompositeUI and CompositeUI.Services
MyData and MyData.ServiceDataSetTableAdapters

<Service()> _
Private _appUser as ServiceDataSet.UserRow

Public ReadOnly Property User() as serviceDataSet.UserRow
Return _appUser
End Get
End Property

I also have one function the ValidatesUser

When I run this I get the ServiceMissingException
"Additional information: Service HITS.Common.Services.UserService is not available in the current context."

Can anyone point me in the right direction?
Jun 28, 2007 at 11:47 AM
Edited Jun 28, 2007 at 11:50 AM
You probably have to instantiate the service in the WorkItem. "ServiceDependency" will only search for an already instantiated service.
Use the "CreateNew" attribute on your property to set it to a new instance.

Check the quickstart projects to find out more about ObjectBuilder usage.
Jun 28, 2007 at 2:44 PM
Ok, I took your suggestion, The only way I could get this to work is comment out the ServiceDependency and add the CreateNew attribute to the property like you suggested. So is this UserService actually loaded as a service or just a class that has been instantiated. Is the service already loaded based on the Common.Dll being listed in the ProfileCatalog? Am I confused or what?

Public Class UserLoginController
Inherits Controller

Private _userService As UserService

'<ServiceDependency()> _
<CreateNew()> _
Public WriteOnly Property UserService() As UserService
Set(ByVal value As UserService)
_userService = value
End Set
End Property
Jun 29, 2007 at 3:54 PM

Since you added the CreateNew decorator to your property, that object is created, but that behavior is not the same as getting a reference of that service with dependency injection. I'd recommend you to read "Getting References to Services" and "Adding Services" sections from SCSF's help or the “Add Service” article from Cabpedia (

In order to load the service via the Object Builder (allowing loosed coupling), you need to do the following:

<Service()> _
Public Class MyService
End Class

This will tell your application to load that service. From that moment on, you will be able to get that service by doing this:

Dim service As IMyService

<ServiceDependency()> _
Public WriteOnly Property MyService() As IMyService
service = value
End Set
End Property

Hope it helps!

Luciano G. Panaro