Search code examples
catel

RegistrationType.Transient for only some viewmodels


I was wondering if it's possible in Catel to specify that some viewmodels are by default with RegistrationType.Transient. I mean if a user opens 2 times the sameviewmodel (for example to work on different orders) I want to have the viewmodel to be a new one. Is this possible using an interceptor? If needed I can decorate the viewmodels with a custom attribute

Thanks


Solution

  • ViewModels are always transient. This means that a new view model will be created for you when you need one.

    This is all done by the IViewModelFactory. Since everything in Catel can be customized / replaced, you can implement your own IViewModelFactory and return an existing instance for some cases.

    All the currently alive view models are retrievable via the IViewModelManager.

    For more information, see the docs.