Voi*_*ice 3 .net unity-container
我正在为我的项目使用Unity App Block(版本1.2.0.0).我有一个Unity容器BuildUp方法的问题,我正在使用我的ascx控件.这是一些代码(非常简单)
public class BaseUserControl<T>:UserControl where T:class
{
protected override void OnInit(EventArgs e)
{
InjectDependencies();
base.OnInit(e);
}
protected virtual void InjectDependencies()
{
var context = HttpContext.Current;
if (context == null)
{
return;
}
var accessor = context.ApplicationInstance as IContainerAccessor;
if (accessor == null)
{
return;
}
var container = accessor.Container;
if (container == null)
{
throw new InvalidOperationException("No Unity container found");
}
container.BuildUp<T>(this as T);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的解决方案中,在ascx控件的基本控件中调用此方法.这里应该注入儿童控制的属性:
[Dependency]
private IStock Stock { get; set; }
Run Code Online (Sandbox Code Playgroud)
因此,在建立股票房产后仍然是空的.Resolve方法适用于具有相同容器和配置的IStock.我尝试使用只有一个属性IStock的简单测试类进行构建并获得相同的结果.那么积累会有什么问题呢?