Take the 2-minute tour ×

I want to inject a string value into a property using Unity. I can't find a syntax that works. In this case, PutBunniesHere

In this case the error is it doesn't recognise "type" as a valid attribute of value. I added that because it couldn't resolve the type before.

The class has this property:

    public string PutBunniesHere { get; set; }

And this is the config I'm using for unity.

  <unity2 xmlns="http://schemas.microsoft.com/practices/2010/unity">
  <alias alias="IInjectMe1" type="CommonLib.IInjectMe1, CommonLib"/>
  <alias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
  <container name="unity2">
    <register type="CommonLib.IInjectMe2, CommonLib" name="Injected2" mapTo="CommonLib.InjectMe2, CommonLib">
      <lifetime type="singleton"/>
        <param name="theDependency" dependencyType="IInjectMe1" />
      <property name="PutBunniesHere">
        <value value="my bunnies" type="System.String"/>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Ok, solved the problem. Once again it was a problem with having a name on the register element. This makes value on the value element take on a different meaning. value means name of a registered type, or a type if there is a name attribute on the parent register element. Take out the name and value means a value (and possibly also a type)


share|improve this answer
add comment

Your Answer


