Is it possible to have independent parameters with constructor injection?

Sep 25, 2008 at 4:30 PM
I am wondering if I can use a specific instance of other objects with constuctor injection.

For example

my class's constructor is

public myClass(IDependentSomething objA, SomethingElse objB)

I want objA to be set by unity but I want to pass the value for objB.  Something like

SomethingElse temp = new SomethingElse();

I know the above doesn't work but is there another way to make that work?  I saw this post which shows how to pass value types

but I want to pass an object and I don't want its value to be declared in the configuration.  Any ideas?
Sep 26, 2008 at 12:38 PM
Sounds like what you are looking for is RegisterInstance.  An excerpt from the documentation follows:

EmailService myEmailService = new EmailService();

If this is not what your looking for I think you'll find the "Setting Up the Unity Container" section under "Key Scenarios" in the Unity documentation very interesting reading - it has numerous scenarios to include the above (I copied the code from it).

Sep 26, 2008 at 4:12 PM
That's it exactly.  Don't know how I missed it (ok, yes I do...I'm a bit of a noob :)

Thanks for your help....again!