简体   繁体   English

(Commerce Server)如何在不实例化新的MarketingContext对象的情况下获取PageGroup []

[英](Commerce Server) How to get the PageGroup[] without instancing a new MarketingContext object

If you take a look at Tom Schultz's Blog , you'll see that he says that if you instance your own Context objects (such as the CommerceContext object), an instance of the SiteConfigReadOnlyFreeThreaded class created in memory as well, and you can't do anything to destroy it. 如果查看Tom Schultz的Blog ,您会发现他说如果您实例化自己的Context对象(例如CommerceContext对象),那么也会在内存中创建SiteConfigReadOnlyFreeThreaded类的实例,并且您不能做任何破坏它的事情。 If you do this enough times, you'll eventually get warnings in your Application Log. 如果这样做足够多次,最终您将在应用程序日志中收到警告。 Here's what the warning looks like: 这是警告的样子:

The Commerce Server runtime has detected that more than # instances of the SiteConfigReadOnlyFreeThreaded object have been created. Commerce Server运行时检测到已创建了#个以上的SiteConfigReadOnlyFreeThreaded对象实例。 Creating many SiteConfigReadOnlyFreeThreaded instances will negatively affect the performance of the site. 创建许多SiteConfigReadOnlyFreeThreaded实例会对站点的性能产生负面影响。 Please refer to the Commerce Server documentation for the recommended use of the SiteConfigReadOnlyFreeThreaded object. 请参考Commerce Server文档以获取对SiteConfigReadOnlyFreeThreaded对象的推荐使用。

You'll also see that Tom says to use the the Current property of the Context objects to avoid this error, much like this: 您还将看到Tom表示要使用Context对象的Current属性来避免此错误,就像这样:

ContentSelector cso = CommerceContext.Current.TargetingSystem.SelectionContexts["advertising"].GetSelector();

Doing so re-uses the same singleton instance to avoid re-creating the SiteConfigReadOnlyFreeThreaded object every time you instance a new CommerceContext class. 这样做会重复使用相同的单例实例,以避免每次您实例化新的CommerceContext类时都重新创建SiteConfigReadOnlyFreeThreaded对象。

With me so far? 到目前为止和我在一起? Good :) 好:)

Here's what I'm really trying to do: Get a list of all of the Page Groups set up in the Marketing section of Commerce Server. 这是我真正想做的事情:获取在Commerce Server的“市场营销”部分中设置的所有页面组的列表。 As far as my knowledge goes, here's the only way to do it: 据我所知,这是唯一的方法:

using (MarketingContext ctx = MarketingContext.Create("MyCommerceSite", "MyMarketingAuthorizationStore", AuthorizationMode.NoAuthorization))
{
    PageGroup[] pageGroups = ctx.PageGroups.GetAllPageGroups();
}

As you can see, I'm creating a MarketingContext class, which also creates a SiteConfigReadOnlyFreeThreaded in memory as well, each time it's called (which happens to be frequently). 如您所见,我正在创建一个MarketingContext类,该类还在每次调用时也会在内存中创建一个SiteConfigReadOnlyFreeThreaded(这很常见)。

Is there a way to get the list of all page groups configured without instancing an entirely new MarketingContext object each time I want to do it? 有没有一种方法可以配置所有页面组的列表,而无需每次我都想实例化一个全新的MarketingContext对象?

I did some digging, and found the following: 我做了一些挖掘,发现以下内容:

By default, Microsoft sets the threshold for these warnings even cropping up in the error log to 100. It turns out that these warnings are absolutely benign if they are staying under 100 in count consistently. 默认情况下,Microsoft将这些警告的阈值设置为甚至在错误日志中突然出现的阈值也设置为100。事实证明,如果这些警告的计数始终低于100,则它们是绝对良性的。

In my case, I had set the threshold for showing errors to 2, just to show every instance that cropped up, regardless of whether it was a valid concern or not. 就我而言,我已将显示错误的阈值设置为2,以显示出现的每个实例,而不管它是否是一个有效的关注点。 I've sense upped the limit back to 100, and I haven't seen any adverse affects thus far. 我已经将上限提高到100,并且到目前为止,我还没有看到任何不利影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM