For "dependency injection", the most common method is "Set Value injection" (that is, injection through the setter attribute). For classes that require many dependencies, the complexity of manually writing attributes one by one has left me intolerable. So I wrote a small vs2003 plug-in. You only need to enter the type and attribute name to automatically generate attributes at the place specified by the editor, and multiple attributes can be generated at a time. (I tried the property auto-generated function in vs2005, and it is not that easy to use :))
After this plug-in is installed, a menu item "propertycreatoraddin" will appear at the top of the shortcut menu of vs2003 right-click ":
Click this menu and the following window will appear:
For example, if you enter "int connectioncount, string servername" in the textbox of "attribute string" and click "generate", the following code is generated in the Editor:
# Region connectioncount
Private int connectioncount = 0;
Public int connectioncount
{
Get
{
Return this. connectioncount;
}
Set
{
This. connectioncount = value;
}
}
# Endregion
# Region servername
Private string servername = "";
Public String servername
{
Get
{
Return this. servername;
}
Set
{
This. servername = value;
}
}
# Endregion
Note the following when entering the attribute string:
(1) type and attribute names are separated by a space.
(2) If multiple attributes need to be generated, each attribute is separated by a comma (, as in the example ).
(3) The two checkboxes on the plug-in interface are used to control the "read-only" attribute and "Write-only" attribute.
Download the propertycreatoraddin Installer