public void CreateExecutor_should_return_a_TypedControllerExecutor_ready_to_use() { var provider = new TypedControllerExecutorProvider {ExecutorFactory = new ExportFactory<TypedControllerExecutor>(GetExecutor)}; var data = new RouteData(); var meta = new TypedControllerMeta(null, null); var executor = (TypedControllerExecutor) provider.CreateExecutor(meta, data, null); Assert.AreSame(data, executor.RouteData); Assert.AreSame(meta, executor.Meta); }
public void CreateExecutor_should_return_a_TypedControllerExecutor_ready_to_use() { var provider = new TypedControllerExecutorProvider { ExecutorFactory = new ExportFactory <TypedControllerExecutor>(GetExecutor) }; var data = new RouteData(); var meta = new TypedControllerMeta(null, null); var executor = (TypedControllerExecutor)provider.CreateExecutor(meta, data, null); Assert.AreSame(data, executor.RouteData); Assert.AreSame(meta, executor.Meta); }
public override ControllerMeta Create(RouteData data) { TypedControllerMeta meta = null; var accessor = httpContext.ApplicationInstance as IContainerAccessor; if (accessor != null) { var container = accessor.Container; var controllerName = data.GetRequiredString("controller").ToLowerInvariant(); if (!container.Kernel.HasComponent(controllerName)) return null; var args = CreateArgs(); var controller = container.Resolve<object>(controllerName, args); var descriptor = DescriptorBuilder.Build(controller.GetType()); meta = new TypedControllerMeta(controller, descriptor); } return meta; }
// No side effects public override ControllerMeta Create(RouteData data, HttpContextBase context) { //data.GetRequiredString("controller"); var controllerName = (string) data.Values["controller"]; if (controllerName == null) return null; var controllerType = _validTypes. Where(t => string.CompareOrdinal(t.Item1, controllerName) == 0). Select(t => t.Item2).FirstOrDefault(); if (controllerType == null) return null; var descriptor = DescriptorBuilder.Build(controllerType); var controller = Activator.CreateInstance(controllerType); var meta = new TypedControllerMeta(controller, descriptor); return meta; }