Problems with the Unity BuildUp Method

I am using the Unity App Block for my project (version 1.2.0.0). I have a problem with the Unity Container BuildUp method that I use for my ascx controls. Here is some code (which is 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 the base control for the ascx controls in my solution. And here is the property that should be introduced in child control:

 [Dependency]
  private IStock Stock { get; set; }

So, after creating the stock property, it is still empty. The Resolve method is great for IStock with the same container and configuration. I tried buildup with a simple test class with only one IStock property and got the same result. So what could be wrong with buildup?

+3
source share
1

, . : IStock buildup . , - .

+5

Source: https://habr.com/ru/post/1736689/


All Articles