开发者

How do I access my public Global.asx.cs property from a business class?

I have a property on my Global.asax.cs class that I need to access from a business class, i.e. using HttpContext.Current.

How do I do this?

Global.asax.cs (in a web project)

public partial class Global : System.Web.HttpApplication
{



    public static ProxyGenerator Generator = new ProxyGenerator();

Business class (in a separate business project)

var generator = ((Sei.Osp.Web.Global)HttpContext.Current.ApplicationInstance)

This obviously doesn't work and I don't want to reference the whole web project in the business project as it will create a circular reference (the business project is already 开发者_如何学运维referenced in the web project)

UPDATE: To clarify - the property I'm creating holds an instance of the Castle Dynamic Proxy Generator class. I've read that you shouldn't just create this all over the place. So I thought I'd create it in my Global.asax.cs and then just use that instance wherever I need to create a proxy class (I'm using it to do AOP)

Is there a better way of doing this?


A better technique would be to create a class (possibly static) with the public static property you want, then reference it from both Global.asax.cs and your business class.

The class could be in your business project, or in a separate project referenced by both your business project and the web project.


Your business classes need to be independent of your web site. You need to reevaluate your reasons for doing it this way. Either the business class doesn't really need access to the property, or the property doesn't need to be in global.asax.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜