Global variables for setting configurations ASP.NET MVC

核能气质少年 提交于 2019-12-11 15:32:47

问题


I wanted to define a global variable in ASP.NET MVC project which will have static configurations details. Like context name, project name etc. Actually I am working on developing reusable component for which you can set all these variables and include them in the project such that they work. Just to give an example

using PROJECT_NAME.Models;
using PROJECT_NAME.BizLogic;
PROJECT_CONTEXT db= new PROJECT_CONTEXT;
and rest of the code follows

This way if I code the components, I think I can use them in any project and all I need to do is set these global variables (or rather reference). Please help me with the following question 1. How can we set such global variable 2. Is there a better way of doing this.

Thanks in advance for your help :)


回答1:


One answer is here: https://stackoverflow.com/a/5119154/538387

but the best and most professional way to do it, is to implement a thread-safe singletone pattern:

http://csharpindepth.com/Articles/General/Singleton.aspx



来源:https://stackoverflow.com/questions/12890776/global-variables-for-setting-configurations-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!