1

我正在尝试重置我的 IDataService(它是我与 WCF 数据服务交互的包装器)并存储在 SimpleIoc.Default 中,以便我可以清空上下文以及它正在跟踪的实体。我不想使用从容器中删除所有内容的重置。我在启动时注册了我的 IDataService: SimpleIoc.Default.Register<IDataService, DataService>();

我正在尝试这个,但它没有像我预期的那样工作,我得到了这个异常:

{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;
    }
}
4

1 回答 1

1

你是对的,这是一个错误。我将在下一个版本中修复它。

如果您需要有关您的特定项目的更多信息,请与我联系,我可以告诉您如何在源代码中修复它并构建您自己的版本。

干杯,劳伦特

于 2012-05-20T16:49:39.607 回答