设置配置ASP.NET MVC全局变量 [英] Global variables for setting configurations ASP.NET MVC
问题描述
我想定义的ASP.NET MVC项目,这将有静态配置的详细信息的全局变量。像上下文名称,项目名称等等。其实我的工作在开发可重用的组件,而您可以将所有这些变量和它们包括在项目中,使得他们的工作。
只是举个例子
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
这样,如果我code中的成分,我想我可以在任何项目中使用它们,我需要做的就是设置这些全局变量(或者说参考)。
请帮我用下面的问题
1.我们如何设置这样的全局变量
2.是否有这样做的更好的方法。
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 :)
推荐答案
一个答案就在这里:
http://stackoverflow.com/a/5119154/538387
但要做到这一点最好的和最专业的方式,是实现线程安全singletone模式:
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
这篇关于设置配置ASP.NET MVC全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!