Exemplo n.º 1
0
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            var nestedContainer = this.container.GetNestedContainer();

            requestContext.HttpContext.Items[NestedContainerKey] = nestedContainer;

            ControllerBase controllerBase = null;

            Func <ControllerContext> ctxtCtor = () => controllerBase == null ? null : controllerBase.ControllerContext;

            //controllerBase == null ? null : controllerBase.ControllerContext;

            nestedContainer
            .Configure(cfg =>
            {
                cfg.For <RequestContext>().Use(requestContext);
                cfg.For <HttpContextBase>().Use(requestContext.HttpContext);
                cfg.For <Func <ControllerContext> >().Use(ctxtCtor);
                cfg.For <IFlashMessenger>()
                .HybridHttpOrThreadLocalScoped()
                .Use(x =>
                {
                    //var tempData = x.GetInstance<Func<ControllerContext>>()().Controller.TempData;
                    var flashMessenger = new WebFlashMessenger(container.GetInstance <IResourcesLocator>(), x.GetInstance <Func <ControllerContext> >());
                    //   tempData["FlashMessenger"] = flashMessenger;
                    return(flashMessenger);
                });
            });

            var controller = nestedContainer.TryGetInstance <IController>(controllerName);

            controllerBase = controller as ControllerBase;

            if (controller == null)
            {
                throw new HttpException(
                          (int)HttpStatusCode.NotFound,
                          string.Format(CultureInfo.CurrentUICulture, "No controller found for {0} at path {1}.", new object[] { controllerName, requestContext.HttpContext.Request.Path }));
            }



            return(controller);
        }
        public override IController CreateController(RequestContext requestContext, string controllerName)
        {
            var nestedContainer = this.container.GetNestedContainer();

            requestContext.HttpContext.Items[NestedContainerKey] = nestedContainer;

            ControllerBase controllerBase = null;

            Func<ControllerContext> ctxtCtor = () => controllerBase == null ? null : controllerBase.ControllerContext;
                //controllerBase == null ? null : controllerBase.ControllerContext;

            nestedContainer
                .Configure(cfg =>
                               {
                                   cfg.For<RequestContext>().Use(requestContext);
                                   cfg.For<HttpContextBase>().Use(requestContext.HttpContext);
                                   cfg.For<Func<ControllerContext>>().Use(ctxtCtor);
                                   cfg.For<IFlashMessenger>()
                                       .HybridHttpOrThreadLocalScoped()
                                       .Use(x =>
                                           {
                                               //var tempData = x.GetInstance<Func<ControllerContext>>()().Controller.TempData;
                                               var flashMessenger = new WebFlashMessenger(container.GetInstance<IResourcesLocator>(), x.GetInstance<Func<ControllerContext>>());
                                                 //   tempData["FlashMessenger"] = flashMessenger;
                                                    return flashMessenger;
                                                });
                               });

            var controller = nestedContainer.TryGetInstance<IController>(controllerName);

            controllerBase = controller as ControllerBase;

            if (controller == null)
            {
                throw new HttpException(
                    (int)HttpStatusCode.NotFound,
                    string.Format(CultureInfo.CurrentUICulture, "No controller found for {0} at path {1}.", new object[] { controllerName, requestContext.HttpContext.Request.Path }));
            }

       

            return controller;
        }