Resolving an unregistred type by name

Sep 9, 2008 at 9:39 AM
Edited Sep 9, 2008 at 9:44 AM

Hi,

According to this note at: http://msdn.microsoft.com/en-us/library/cc440957.aspx:

Note:
If the container does not contain a mapping for the specified combination of type and name, it will raise an exception. Also remember that names are case-sensitive.

This test should throw an exception:

[TestClass]

public class AppleTests

{

    [TestMethod]

    public void CanCreateNonexistingNamedEntry()

    {

        IUnityContainer container = new UnityContainer();

 

        var apple = container.Resolve<Apple>("someRandomString");

 

        Assert.IsNull(apple);

    }

 

    public class Apple { }

}

but it doesn't - it actaully returns an instance ... anyone knows more about this?

Sep 9, 2008 at 6:54 PM
The docs are wrong. In that case, Unity will treat it just like any other unregistered type, and create a new transient instance.