如何摧毁SharePointServiceLocator以使用记录器

时间:2013-07-24 13:06:58

标签: moles pex-and-moles

我试图找出如何骚扰

Microsoft.Practices.SharePoint.Common.ServiceLocation.SharePointServiceLocator.GetCurrentFarmLocator

因为我试图使用

 Microsoft.Practices.SharePoint.Common.Logging.SharePointLogger.WriteToDeveloperTrace

一些帮助或示例?

1 个答案:

答案 0 :(得分:2)

我自己使用SharePointServiceLocator找到了一个解决方案。 基本上我在我的代码上实现了这个:

            var replaceLocator = new ActivatingServiceLocator ( );
            SharePointServiceLocator.ReplaceCurrentServiceLocator ( replaceLocator );
            replaceLocator.RegisterTypeMapping < ILogger, MockLogger > ( InstantiationType.AsSingleton );
            replaceLocator.RegisterTypeMapping < ITraceLogger, MockLogger > ( InstantiationType.AsSingleton );
            replaceLocator.RegisterTypeMapping < IEventLogLogger, MockLogger > ( InstantiationType.AsSingleton );