Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Unity, is it possible to resolve a type from its type alias?

I've registered several types in Unity and given them type aliases as follows:

<typeAliases>
   <typeAlias alias="MyType" type="foo.bar.MyType, foo.bar" />
</typeAliases>

Is it possible to resolve these types by from the container using the aliased name (as opposed to by type), along the lines of:

var myType = container.ResolveByTypeAlias("MyType")

I can't see any way to do this, but wondered if I've missed something.

like image 323
Rob Levine Avatar asked Oct 23 '22 23:10

Rob Levine


1 Answers

No, aliases exist only in the XML configuration. i.e. they only exist at configuration type.

http://msdn.microsoft.com/en-us/library/ff660933(v=pandp.20).aspx details this

Aliases only exist at configuration time. They are not available at run time.

like image 118
Peter Ritchie Avatar answered Oct 31 '22 11:10

Peter Ritchie