我是 Ninject 的新手,需要一些帮助。
我的解决方案包括 web.form(表示层)和多个其他类库项目。
在 web.form 应用程序中,我有一个 NinjectWebCommon cs 文件,其中包含以下内容:
kernel.Bind<HttpContext>()
.ToMethod(ctx => HttpContext.Current).InThreadScope();
kernel.Bind<HttpContextBase>()
.ToMethod(ctx => new HttpContextWrapper(HttpContext.Current)).InTransientScope();
kernel.Bind<MPIBE.DESTINATION.CORE.SiteContext>()
.ToMethod(ctx => new MPIBE.DESTINATION.CORE.SiteContext(
new HttpContextWrapper(HttpContext.Current)
));
我正在尝试获取一个类的实例(遵循构造函数)
public SessionUtilities(SiteContext siteContext)
{
_siteContext = siteContext;
}
我注意到只能从web.forms应用程序中获取实例,而无法从其他项目(类库)中获取。这有意义吗?
我正在尝试通过属性注入获取实例。
[Inject]
public SessionUtilities _sessionUtilities { get; set; }