/// <summary>
        /// Search for usercontrols within the parent control
        /// and inject their dependencies using KernelContainer.
        /// </summary>
        /// <param name="parent">The parent control.</param>
        /// <param name="skipDataBoundControls">if set to <c>true</c> special handling of DataBoundControls is skipped.</param>
        private static void InjectUserControls(Control parent, bool skipDataBoundControls)
        {
            if (parent == null)
            {
                return;
            }

            if (skipDataBoundControls)
            {
                var dataBoundControl = parent as DataBoundControl;
                if (dataBoundControl != null)
                {
                    dataBoundControl.DataBound += InjectDataBoundControl;
                    return;
                }
            }

            foreach (Control control in parent.Controls)
            {
                if (control is UserControl)
                {
                    KernelContainer.Inject(control);
                }

                InjectUserControls(control, skipDataBoundControls);
            }
        }
        /// <summary>
        /// Injects dependencies into web pages and subscribes to their InitComplete
        /// Event to inject usercontrols with their dependencies.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void OnPreRequestHandlerExecute(object sender, EventArgs e)
        {
            var page = this.httpApplication.Context.CurrentHandler as Page;

            if (page == null)
            {
                return;
            }

            KernelContainer.Inject(page);
            page.PreLoad += (src, args) => InjectUserControls(page, false);
        }
 /// <summary>
 /// Raises the <see cref="E:System.Web.UI.Control.Init"></see> event to initialize the page.
 /// </summary>
 /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param>
 protected override void OnInit(EventArgs e)
 {
     base.OnInit(e);
     KernelContainer.Inject(this);
 }
Exemplo n.º 4
0
 /// <summary>
 /// Asks the kernel to inject this instance.
 /// </summary>
 protected virtual void RequestActivation()
 {
     KernelContainer.Inject(this);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WebServiceBase"/> class.
 /// </summary>
 protected WebServiceBase()
 {
     KernelContainer.Inject(this);
 }
 /// <summary>
 /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler"></see> interface.
 /// </summary>
 /// <param name="context">An <see cref="T:System.Web.HttpContext"></see> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param>
 public void ProcessRequest(HttpContext context)
 {
     KernelContainer.Inject(this);
     this.DoProcessRequest(context);
 }
Exemplo n.º 7
0
 public void OnItemAdded(object sender, EventArgs args)
 {
     KernelContainer.Inject(this);
     InternalOnItemAdded(sender, args);
 }