SimpleIOC - either add SetInstance or change GetInstance to support parameters


Hi. Great toolkit, thank you!

If I am not mistaken, neither of these is available, and I would like to see them added. If I am mistaken, please tell me how to do it, or I can ask the question on stackoverflow as you you request.

I would like to have a SetInstance so we can create our own viewmodel and add its instance to the SimpleIOC.

I would like to add parameters to the GetInstance for ViewModel instantiation.
Closed Oct 13, 2014 at 10:40 AM by lbugnion


clairestreb wrote Aug 20, 2012 at 2:56 AM

I want to add that I do not know which ViewModel I am instantiating. I use something like the following
public static object CreateViewModel<T>(string fullVMName, params object[] parameters)
        Type typeOfVM = Type.GetType(fullVMName);
        object vm = Activator.CreateInstance(typeOfVM, params); // this is like xViewModel vm = new xViewModel(...)

lbugnion wrote Oct 13, 2014 at 10:40 AM


You can add an existing instance (for example created as you show above) using the following syntax:
SimpleIoc.Default.Register<Type>(() => instance);