/// <summary>
 /// Resolves singly registered services that support arbitrary object creation.
 /// </summary>
 /// <param name="serviceType">The type of the requested service or object.</param>
 /// <returns>
 /// The requested service or object.
 /// </returns>
 public object GetService(Type serviceType)
 {
     if (!ServiceLocatorManager.HasIgnoreServiceLocator(serviceType))
     {
         if (!serviceType.IsInterface && !serviceType.IsAbstract)
         {
             return(ServiceLocator.Resolve(serviceType));
         }
     }
     return(null);
 }
 /// <summary>
 /// Releases the specified controller.
 /// </summary>
 /// <param name="controller">The controller to release.</param>
 public override void ReleaseController(IController controller)
 {
     if (!ServiceLocatorManager.HasIgnoreServiceLocator(controller))
     {
         var disposable = (controller as IDisposable);
         if (disposable != null)
         {
             disposable.Dispose();
         }
         ServiceLocator.Release(controller);
     }
     base.ReleaseController(controller);
 }
Example #3
0
        /// <summary>
        /// Binds the model by using the specified controller context and binding context.
        /// </summary>
        /// <param name="controllerContext">The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.</param>
        /// <param name="bindingContext">The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.</param>
        /// <returns>
        /// The bound object.
        /// </returns>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="bindingContext "/>parameter is null.</exception>
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var controllerType = controllerContext.Controller.GetType();
            IEnumerable <IInjectableModelBinder> modelBinders;

            if (!ServiceLocatorManager.HasIgnoreServiceLocator(controllerType) && (modelBinders = GetModelBinders()) != null)
            {
                foreach (var modelBinder in modelBinders.Where(x => x.InjectForModelType(bindingContext.ModelType)))
                {
                    return(modelBinder.BindModel(controllerContext, bindingContext));
                }
            }
            return(base.BindModel(controllerContext, bindingContext));
        }
 /// <summary>
 /// Retrieves the controller instance for the specified request context and controller type.
 /// </summary>
 /// <param name="requestContext">The context of the HTTP request, which includes the HTTP context and route data.</param>
 /// <param name="controllerType">The type of the controller.</param>
 /// <returns>
 /// The controller instance.
 /// </returns>
 /// <exception cref="T:System.Web.HttpException">
 ///   <paramref name="controllerType"/> is null.</exception>
 ///
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="controllerType"/> cannot be assigned.</exception>
 ///
 /// <exception cref="T:System.InvalidOperationException">An instance of <paramref name="controllerType"/> cannot be created.</exception>
 protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
 {
     // skips and calls to base if controllerType = null, throw standard MVC exception
     if (!ServiceLocatorManager.HasIgnoreServiceLocator(controllerType))
     {
         var controller             = ServiceLocator.Resolve <IController>(controllerType);
         var controllerAsController = (controller as Controller);
         if (controllerAsController != null)
         {
             controllerAsController.ActionInvoker = GetActionInvoker();
         }
         return(controller);
     }
     return(base.GetControllerInstance(requestContext, controllerType));
 }