0

I'm instantiating a View throught the Unity, and this View has a ViewModel as parameter. However, this ViewModel has three other parameters, which two of them are already configureted on Unity, and the last parameter I need to get from the MainView that open the SecondView. (Crazy, hm?)

This method is called from my MainView (first view) when a button is clicked:

private void ShowAddVersionViewExecute()
{
    Window view = UnityServiceConfigurator.Instance.GetUnityContainer().Resolve<AddVersionView>() as Window;
    view.ShowDialog();
}

This is my AddVersionView (second view), which has its ViewModel as parameter.

public partial class AddVersionView
{
    public AddVersionView(AddVersionViewModel viewModel)
    {
        //InicializeComponents and set the viewModel to DataContext.
    }
}

This is the AddVersionViewModel's constructor

public AddVersionViewModel(IDialogService dialog, AbstractRepository repository, string versionNumber)
{
    //Some code here.
}

The IDialogService and AbstractRepository are resolved by Unity. BUT I want receive the "versionNumber" from the MainView.

  1. How/What am I supposed to do it?
  2. Is there any other way to perform that?

Thanks a lot.

1 Answer 1

2

You can use parameter overrides to supply parameters at resolve time. There are several examples available at http://msdn.microsoft.com/en-us/library/ff660920(v=pandp.20).aspx.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I tried with ParameterOverride and it worked as I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.