Dependency tag and Dependency attribute.

Dec 22, 2009 at 9:28 AM

Hello everybody!

I want to know if dependency attribute, for example:

        public string Field1
            get { return field1; }

correlate with dependency tag. I mean, can  I refer on that property in config file, for example:

<type type="MySecondType">
            <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
                <param name="tet1" parameterType="System.String">
                  <dependency name="test"/>


Thanks in advance!

Dec 27, 2009 at 11:57 PM

They perform similar functions, but the two examples are radically different. In the first, you've got a property, in the second, you've got a constructor parameter.

The attribute says "container, please inject here, and use this name when resolving". It serves to both mark WHAT to inject and HOW. In configuration, on the other hand, the WHAT is determined by the surrounding elements (the <param> element in your example). The <dependency> tag says how - in this case, to call back into the container to resolve the value.

By the way, neither will work unless you've configured the container with a string with the matching name "test" in it.