views:

332

answers:

1

Using Unity in Prism, I would like to send a parameter to the object's constructor like this:

PSEUDO-CODE:

SmartFormPresenter smartFormPresenter1 =
    this.container.Resolve<SmartFormPresenter(customer)>();

But instead I have to instatiate it and then assign a property:

SmartFormPresenter smartFormPresenter1 =
    this.container.Resolve<SmartFormPresenter>();
smartFormPresenter1.ObjectBeingEdited = customer;

Is there any way to send a parameter to the constructor directly?

+1  A: 

Here's a related question that answers this pretty well: http://stackoverflow.com/questions/787001/can-i-pass-constructor-parameters-to-unitys-resolve-method

The only option you have if you want to do this is a scoped container.

IUnityContainer subContainer = this.container.CreateScopedContainer();
subContainer.RegisterInstance<Customer>(customer);
smartFormPresenter1 = subContainer.Resolve<SmartFormPresenter>();
Anderson Imes