If you use spring.net as your IOC container, be sure to pay attention to this problem. --spring.net currently does not support access qualifiers of getter and setter.
We usually use the setter attribute for dependency injection, for example, public Class.
{
# Region B
Private B;
Public B
{
Get {return B ;}
Set {B = value ;}
}
# Endregion
}
Public Class B
{
}
For the above definition, it is completely normal to configure a Class A object in spring.net and inject the dependency of Class B object.
However, suppose that I want the B attribute of the type to only access the derived class of a. We usually add the protected qualifier to the getter of the B attribute, just like this: Public Class
{
# Region B
Private B;
Public B
{
ProtectedGet {return B ;}
Set {B = value ;}
}
# Endregion
}
Public Class B
{
}
In this definition, if the same spring configuration is still used, an exception "object reference is not set to object instance" is thrown-a very common exception.
What kind of pain is it when I look for possible bugs in applications composed of thousands of components following this exception prompt-in fact, my code and configuration are fine, spring.net made a joke. It took me nearly two hours to figure out the joke. So, I don't want your friends to waste our precious time in the future due to the same problem.