在ASP.NET中使用单身的正确方法?

时间:2016-04-24 19:52:19

标签: asp.net asp.net-mvc singleton httpcontext

问题:以下代码是否100%确保每个用户的对象的唯一性(根据我的理解,这意味着每个浏览器(或请求))?

/// <summary>
        /// Ensures the uniqueness for each request. 
        /// </summary>
        private static MultiLanguageProvider Instance
        {
            get
            {
                var currentSession = HttpContext.Current.Session;
                var nameOfInstance = nameof(MultiLanguageProvider);

                if ((currentSession[nameOfInstance] as MultiLanguageProvider).IsNull())
                    currentSession[nameOfInstance] = new MultiLanguageProvider();

                return currentSession[nameOfInstance] as MultiLanguageProvider;
            }
        }

0 个答案:

没有答案