Problems with Unity BuildUp Method
- by Voice
Hi everybody)
I'm using Unity App Block for my project (version 1.2.0.0).
I have a problem with Unity Container BuildUp method which I'm using for my ascx controls. Here is some code (that's pretty simple)
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);
}
}
This method is called in base control for ascx controls in my solution. And here the property that should be injected in child control:
[Dependency]
private IStock Stock { get; set; }
So after buildup Stock property is still empty. Resolve method works fine for IStock with the same container and configuration. I've tried buildup with simple test class with only one property IStock and got the same result. So what can be wrong with buildup?