I’m trying to reset my IDataService (which is a wrapper for my interaction with my WCF Data Service) and is stored in the SimpleIoc.Default so that I can empty out the context and which entities it is tracking. I don’t want to use Reset which removes everything from the containers.
I register my IDataService at startup:
SimpleIoc.Default.Register<IDataService, DataService>();
I’m trying this, but it isn’t working as I expected and I’m getting this exception:
{System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at GalaSoft.MvvmLight.Ioc.SimpleIoc.Register[TInterface,TClass](Boolean createInstanceImmediately)
at GalaSoft.MvvmLight.Ioc.SimpleIoc.Register[TInterface,TClass]()
at Bootstrap.ResetDataService()}
public static void ResetDataService()
{
try
{
SimpleIoc.Default.Unregister<IDataService>();
SimpleIoc.Default.Register<IDataService, DataService>();
}
catch (System.Exception)
{
throw;
}
}
You are right, this is a bug. I will fix it in the next release.
Please contact me if you need more info for your particular project, I can indicate you how to fix it in the source code and build your own version.
Cheers,
Laurent