[ServiceDependency] and [CreateNew]

Topics: CAB & Smart Client Software Factory
Jan 7, 2006 at 9:04 AM
originally posted by: ovidius

Hallo,
I'm learning about CAB following the HOL, and because i'm Italian and i don't know English very well, i'm in difficult to understand some things.

Those attribuse are used to use a service without create an instace of it (I think!?!?).
In the lab 2 we define a controller for the view in this way:

private CustomerQueueController myController;

CreateNew
public CustomerQueueService MyController
{ set { mycontroller=value; }}
in practice we are using the CreateNew Attribute.

In the CustomerQueueController.cs we get a reference to a service by usind the ServiceDependency attribute.
I ask why?
May we use the serviceDependency attribute insted of CreateNew in the CustomerQueueService property?
If not, why?
Which are the differences between this two attributes? they initializes automatically, at run time, an object and provides a reference to it using IoC technique.
Maybe CreateNew is only for Controller and ServiceDependency is only for services?

Thanks. Antonio P.
Jan 8, 2006 at 6:12 PM
originally posted by: jburtch

For a good discussion of the differences in the two attributes look at the earlier thread entitled "ServiceDependency, CreateNew, InjectionConstructor "
here watch for wrapping
http://www.gotdotnet.com/codegallery/messageboard/thread.aspx?id=22f72167-af95-44ce-a6ca-f2eafbf2653c&mbid=c09776ca-f94c-4c83-a80c-75d381cabdd6&threadid=cdb7590b-680b-4ec6-8f71-a7b81611adb5

From the HOL, you'll notice that the ServiceDependency will continue to give you the same object but CreateNew will give you a new object. There is also a Dependency Attribute that looks like it can perform named object injection.

Justin Burtch