Esempio n. 1
0
    /// <summary>
    ///   Registers dependencies, and injects them into new instances of view components in response to each request.
    /// </summary>
    /// <returns>A concrete instance of an <see cref="Controller"/>.</returns>
    public object Create(ViewComponentContext context) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate parameters
      \-----------------------------------------------------------------------------------------------------------------------*/
      Contract.Requires(context, nameof(context));

      /*------------------------------------------------------------------------------------------------------------------------
      | Determine view component type
      \-----------------------------------------------------------------------------------------------------------------------*/
      var type = context.ViewComponentDescriptor.TypeInfo.AsType();

      /*------------------------------------------------------------------------------------------------------------------------
      | Configure and return appropriate view component
      \-----------------------------------------------------------------------------------------------------------------------*/
      if (StandardEditorComposer.IsEditorComponent(type)) {
        return _standardEditorComposer.ActivateEditorComponent(type, _topicRepository);
      }

      throw new InvalidOperationException($"Unknown view component {type.Name}");

    }
Esempio n. 2
0
    /// <summary>
    ///   Registers dependencies, and injects them into new instances of view components in response to each request.
    /// </summary>
    /// <returns>A concrete instance of an <see cref="IController"/>.</returns>
    public object Create(ViewComponentContext context) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Determine view component type
      \-----------------------------------------------------------------------------------------------------------------------*/
      var viewComponentType = context.ViewComponentDescriptor.TypeInfo.AsType();

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish dependencies
      >-------------------------------------------------------------------------------------------------------------------------
      | ### HACK JJC20200725: Typically, we use a singleton life cycle for the hierarchical navigation—and, indeed, we have one
      | defined. During development, however, we'll be using a transient scoped dependency in order to avoid the caching
      | implemented in the singleton version. Prior to deployment, we'll switch back to the singleton.
      \-----------------------------------------------------------------------------------------------------------------------*/
      var coursewareTopicMappingService = (IHierarchicalTopicMappingService<TrackedNavigationTopicViewModel>)null;
      if (viewComponentType.Namespace.Contains("Courses", StringComparison.OrdinalIgnoreCase)) {
        coursewareTopicMappingService = new HierarchicalTopicMappingService<TrackedNavigationTopicViewModel>(
          _topicRepository,
          _topicMappingService
        );
      }

      /*------------------------------------------------------------------------------------------------------------------------
      | Resolve
      \-----------------------------------------------------------------------------------------------------------------------*/

      //Handle standard topic editor view components
      if (StandardEditorComposer.IsEditorComponent(viewComponentType)) {
        return _standardEditorComposer.ActivateEditorComponent(
          viewComponentType,
          _topicRepository
        );
      }

      //Handle GoldSim-specific view components
      return viewComponentType.Name switch {

        nameof(CookiesNoticeViewComponent)
          => new CookiesNoticeViewComponent(),

        nameof(MetadataLookupViewComponent)
          => new MetadataLookupViewComponent(_topicRepository),

        nameof(MenuViewComponent)
          => new MenuViewComponent(_topicRepository, _hierarchicalTopicMappingService),

        nameof(PageLevelNavigationViewComponent)
          => new PageLevelNavigationViewComponent(_topicRepository, _hierarchicalTopicMappingService),

        nameof(CallsToActionViewComponent)
          => new CallsToActionViewComponent(_topicRepository, _hierarchicalTopicMappingService),

        nameof(FooterViewComponent)
          => new FooterViewComponent(_topicRepository, _hierarchicalTopicMappingService),

        nameof(CourseListViewComponent)
          => new CourseListViewComponent(_topicRepository, coursewareTopicMappingService),

        nameof(UnitListViewComponent)
          => new UnitListViewComponent(_topicRepository, coursewareTopicMappingService),

        nameof(LessonListViewComponent)
          => new LessonListViewComponent(_topicRepository, coursewareTopicMappingService),

        nameof(LessonPagingViewComponent)
          => new LessonPagingViewComponent(_topicRepository, _topicMappingService),

        _ => throw new Exception($"Unknown view component {viewComponentType.Name}")

      };
    }