我在当前项目中遇到了以前从未遇到过的Glass Mapper问题。
在 Sitecore 初始化之后,Database
我的 GlassContext ( ISitecoreContext
) 中的属性立即为空。
// After Sitecore initialization, sometimes the glass context database is not initialized yet.
if (this.glassContext == null || this.glassContext.Database == null)
{
this.glassContext = DependencyInjection.Container.Resolve<ISitecoreContext>();
// Now I have a valid this.glassContext.Database ...
}
当我向我的 DI 框架(Windsor,所以 Glass 的默认值)询问一个实例时,它返回给我一个具有有效数据库属性的实例。
暂时我在检索任何项目之前做这个检查,它只需要这个检查一次(之后它很好,直到下一次初始化),但真的很想知道是什么导致了这个。
可能很有趣:所有的项目请求(获取项目、铸造项目等)都是通过一个服务完成的,该服务ISitecoreContext
在其构造函数中初始化。
有ItemService
生活方式Singleton ,ISitecoreContext
有生活方式Transient