Print Page | Close Window

How do I understand the [InjectionConstructor] Tag?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=349
Printed Date: 12-Jun-2026 at 2:56am


Topic: How do I understand the [InjectionConstructor] Tag?
Posted By: Linguinut
Subject: How do I understand the [InjectionConstructor] Tag?
Date Posted: 01-Aug-2007 at 1:49pm
In the SalesRepModule.cs class there is this constructor:
 
/// <summary>Ctor.</summary>
[InjectionConstructor]
public SalesRepModule([ServiceDependency] WorkItem rootWorkItem) {
_rootWorkItem = rootWorkItem;
}
 
When the Object Builder does its magic, what object is this class being injected into?  In other words, something is going to depend on this module...how do I know what that is?  Am I asking the right question, even?
 
Thanks,
Bill
 



Replies:
Posted By: Bill Jensen
Date Posted: 01-Aug-2007 at 4:40pm
This is called "constructor injection".  The [ServiceDependency] attribute causes the object builder to provide the root workitem as a parameter of the constructor.  It is injecting the workitem INTO the SalesRepModule.
 
Bill J


Posted By: Linguinut
Date Posted: 01-Aug-2007 at 5:18pm
Hmmm...workitem into module...opposite of what I was thinking.  Must meditate on that.


Posted By: Linguinut
Date Posted: 02-Aug-2007 at 7:26am
So, trying to understand the syntax, could we say something like this?
 
[InjectionConstructor]
public SalesRepModule([ServiceDependency] workItem rootWorkItem)
{
     _rootWorkItem = rootWorkItem;
}
 
means:
 
Th object builder by passing in the workitem constructs the sales rep object with a dependency on the workitem.
 
Once the object is created and the dependency declared, then the new object has access to the workitem which it uses to add the controller and run it (load method).  Right?



Print Page | Close Window