从会话中获取值并在构造函数中设置

问题描述 投票:0回答:1

我有一个包含构造函数和函数的类,这只是一个例子

public class CheckValue
    {
        private readonly ConcurrentDictionary<string, ValuesForTest> _values;
        public CheckValue()
        {
            _values = JsonConvert
                .DeserializeObject<ConcurrentDictionary<string, ValuesForTest>>(HttpContext.Current.Session["valueInSession"]);
        }
    }

我需要在 CheckValue 类的所有函数中使用值 我的问题是我不知道我的代码是否干净,我使用了 oop 的最佳实践

c# algorithm oop code-cleanup
1个回答
0
投票

我建议传递您想要在构造函数类中使用的值

© www.soinside.com 2019 - 2024. All rights reserved.