BuildUp method with name parameter

Oct 5, 2010 at 10:03 AM

Hi.

I am newbie to Unity.

While going through the documentation, I have understood that BuildUp method can inject dependencies to the objects that are created out of the container.

BuildUp also has one overloaded method with parameter called name(string). I am not able to understand what is this name used for?

Can someone please explain with example.

Thanks in advance.

Thanks,

Nisdes

 

Oct 5, 2010 at 10:32 AM
Edited Oct 5, 2010 at 10:33 AM

Here's a sample, suppose you have two registrations for type IPerson.

container.RegisterType<IPerson, Person>(new InjectionProperty("Name", "A"));

container.RegisterType<IPerson, Person>("person2", new InjectionProperty("Name", "B"));

doing this:

IPerson person = new Person();
IPerson newPerson = container.BuildUp(person, "person2");

will result to the newPerson variable having the value "B" for its Name property.

Doing this:

IPerson newPerson = container.BuildUp(person)

will result to the newPerson variable having the value "A" for its Name property.

 

It makes a distinction between registrations to determine what dependencies to inject.  Much the same way how the name parameter functions in the Resolve method.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 5, 2010 at 12:11 PM

Thanks Sarah for concise and self explanatory example for clearing up the BuildUp overload method.

 

Thanks,

Nisdes