private ILocatorScoped _Create(ILocator locator) { if (!(locator is ILocatorWithCreateScope creator)) { throw new ArgumentException($"{locator.GetType().FullName} doesn't implement {typeof(ILocatorWithCreateScope).FullName}!"); } var scope = creator.CreateScope(); var accessor = scope.Get <ILocatorScopedAccessor>(); if (!(accessor is ILocatorScopedWithSet setter)) { throw new Exception($"{accessor.GetType().FullName} must implement {typeof(ILocatorScopedWithSet).FullName}!"); } setter.SetCurrentScopedLocator(scope); if (_locatorAmbient is ILocatorAmbientWithSet settable) { scope.OnDispose(() => settable.SetCurrentScopedLocator(null)); settable.SetCurrentScopedLocator(scope); } return(scope); }
/// <summary> /// Creates MVC controller /// </summary> /// <param name="requestContext"></param> /// <param name="controllerName"></param> /// <returns></returns> public override IController CreateController(RequestContext requestContext, string controllerName) { if (requestContext is null) { throw new ArgumentNullException(nameof(requestContext)); } if (controllerName is null) { throw new ArgumentNullException(nameof(controllerName)); } var controllerType = base.GetControllerType(requestContext, controllerName); if (controllerType is null) { throw new NullReferenceException($"Controller type {controllerType.FullName} not found"); } var controller = ResolveLocator(requestContext).Get(controllerType) as IController; if (controller is null) { throw new ApplicationException(string.Format("No controller with name '{0}' found in {1}", controllerName, _Locator.GetType().FullName)); } return(controller); }