/*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Establishes a new instance of the <see cref="SampleControllerFactory"/>, including any shared dependencies to be used
    ///   across instances of controllers.
    /// </summary>
    /// <remarks>
    ///   The constructor is responsible for establishing dependencies with the singleton lifestyle so that they are available
    ///   to all requests.
    /// </remarks>
    public SampleActivator(string connectionString) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Initialize Topic Repository
      \-----------------------------------------------------------------------------------------------------------------------*/
      var                       sqlTopicRepository              = new SqlTopicRepository(connectionString);
      var                       cachedTopicRepository           = new CachedTopicRepository(sqlTopicRepository);
      _                                                         = new PageTopicViewModel();

      /*------------------------------------------------------------------------------------------------------------------------
      | Preload repository
      \-----------------------------------------------------------------------------------------------------------------------*/
      _topicRepository                                          = cachedTopicRepository;
      _typeLookupService                                        = new DynamicTopicViewModelLookupService();
      _topicMappingService                                      = new TopicMappingService(_topicRepository, _typeLookupService);
      _                                                         = _topicRepository.Load();

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish hierarchical topic mapping service
      \-----------------------------------------------------------------------------------------------------------------------*/
      _hierarchicalMappingService = new CachedHierarchicalTopicMappingService<NavigationTopicViewModel>(
        new HierarchicalTopicMappingService<NavigationTopicViewModel>(
          _topicRepository,
          _topicMappingService
        )
      );

    }
Example #2
0
        /*==========================================================================================================================
        | CONSTRUCTOR
        \-------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        ///   Establishes a new instance of the <see cref="GoldSimActivator"/>, including any shared dependencies to be used
        ///   across instances of controllers.
        /// </summary>
        /// <remarks>
        ///   The constructor is responsible for establishing dependencies with the singleton lifestyle so that they are available
        ///   to all requests.
        /// </remarks>
        public GoldSimActivator(IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
        {
            /*------------------------------------------------------------------------------------------------------------------------
              | Verify dependencies
              \-----------------------------------------------------------------------------------------------------------------------*/
              Contract.Requires(configuration, nameof(configuration));
              Contract.Requires(webHostEnvironment, nameof(webHostEnvironment));

              /*------------------------------------------------------------------------------------------------------------------------
              | SAVE STANDARD DEPENDENCIES
              \-----------------------------------------------------------------------------------------------------------------------*/
              _configuration        = configuration;
              _webHostEnvironment   = webHostEnvironment;
              var connectionString      = configuration.GetConnectionString("OnTopic");
              var sqlTopicRepository    = new SqlTopicRepository(connectionString);
              var cachedTopicRepository = new CachedTopicRepository(sqlTopicRepository);

              /*------------------------------------------------------------------------------------------------------------------------
              | PRELOAD REPOSITORY
              \-----------------------------------------------------------------------------------------------------------------------*/
              _topicRepository          = cachedTopicRepository;
              _typeLookupService        = new CompositeTypeLookupService(
                                    new GoldSimTopicViewModelLookupService(),
                                    new TopicViewModelLookupService(),
                                    new EditorViewModelLookupService()
                                  );
              _topicMappingService      = new TopicMappingService(_topicRepository, _typeLookupService);

              _topicRepository.Load();

              /*------------------------------------------------------------------------------------------------------------------------
              | INITIALIZE EDITOR COMPOSER
              \-----------------------------------------------------------------------------------------------------------------------*/
              _standardEditorComposer   = new(_topicRepository, _webHostEnvironment);

              /*------------------------------------------------------------------------------------------------------------------------
              | CONSTRUCT SMTP CLIENT
              \-----------------------------------------------------------------------------------------------------------------------*/
              var postmarkApiKey        = _configuration.GetValue<string>("Postmark:ApiKey");
              var postmarkClient        = new PostmarkClient(postmarkApiKey);

              _smtpService              = new PostmarkSmtpService(postmarkClient);

              /*------------------------------------------------------------------------------------------------------------------------
              | CONSTRUCT HIERARCHICAL TOPIC MAPPING SERVICES
              \-----------------------------------------------------------------------------------------------------------------------*/
              _hierarchicalTopicMappingService = new CachedHierarchicalTopicMappingService<Models.NavigationTopicViewModel>(
            new HierarchicalTopicMappingService<Models.NavigationTopicViewModel>(
              _topicRepository,
              _topicMappingService
            )
              );

              _coursewareTopicMappingService = new CachedHierarchicalTopicMappingService<TrackedNavigationTopicViewModel>(
            new HierarchicalTopicMappingService<TrackedNavigationTopicViewModel>(
              _topicRepository,
              _topicMappingService
            )
              );
        }
        /*==========================================================================================================================
        | CONSTRUCTOR
        \-------------------------------------------------------------------------------------------------------------------------*/
        /// <summary>
        ///   Establishes a new instance of the <see cref="SampleControllerFactory"/>, including any shared dependencies to be used
        ///   across instances of controllers.
        /// </summary>
        public SampleControllerFactory() : base()
        {
            /*------------------------------------------------------------------------------------------------------------------------
            | ESTABLISH DATABASE CONNECTION
            \-----------------------------------------------------------------------------------------------------------------------*/
            var connectionString   = ConfigurationManager.ConnectionStrings["OnTopic"].ConnectionString;
            var sqlTopicRepository = new SqlTopicRepository(connectionString);

            /*------------------------------------------------------------------------------------------------------------------------
            | SAVE STANDARD DEPENDENCIES
            \-----------------------------------------------------------------------------------------------------------------------*/
            _topicRepository     = new CachedTopicRepository(sqlTopicRepository);
            _typeLookupService   = new TopicViewModelLookupService();
            _topicMappingService = new TopicMappingService(_topicRepository, _typeLookupService);
            _rootTopic           = _topicRepository.Load();

            /*------------------------------------------------------------------------------------------------------------------------
            | CONSTRUCT HIERARCHICAL TOPIC MAPPING SERVICE
            \-----------------------------------------------------------------------------------------------------------------------*/
            var service = new HierarchicalTopicMappingService <NavigationTopicViewModel>(
                _topicRepository,
                _topicMappingService
                );

            _hierarchicalTopicMappingService = new CachedHierarchicalTopicMappingService <NavigationTopicViewModel>(
                service
                );
        }
Example #4
0
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Establishes a new instance of the <see cref="SampleActivator"/>, including any shared dependencies to be used across
    ///   instances of controllers.
    /// </summary>
    /// <remarks>
    ///   The constructor is responsible for establishing dependencies with the singleton lifestyle so that they are available
    ///   to all requests.
    /// </remarks>
    public SampleActivator(string connectionString, IWebHostEnvironment webHostEnvironment) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Verify dependencies
      \-----------------------------------------------------------------------------------------------------------------------*/
      Contract.Requires(connectionString, nameof(connectionString));
      Contract.Requires(webHostEnvironment, nameof(webHostEnvironment));

      /*------------------------------------------------------------------------------------------------------------------------
      | Initialize Topic Repository
      \-----------------------------------------------------------------------------------------------------------------------*/
      var sqlTopicRepository    = new SqlTopicRepository(connectionString);
      var cachedTopicRepository = new CachedTopicRepository(sqlTopicRepository);

      /*------------------------------------------------------------------------------------------------------------------------
      | Preload repository
      \-----------------------------------------------------------------------------------------------------------------------*/
      _topicRepository          = cachedTopicRepository;
      _typeLookupService        = new EditorViewModelLookupService();
      _topicMappingService      = new TopicMappingService(_topicRepository, _typeLookupService);
      _                         = _topicRepository.Load();

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish standard editor composer
      \-----------------------------------------------------------------------------------------------------------------------*/
      _webHostEnvironment       = webHostEnvironment;
      _standardEditorComposer   = new StandardEditorComposer(_topicRepository, _webHostEnvironment);

    }
Example #5
0
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Establishes a new instance of a <see cref="StandardEditorComposer"/> with dependencies which are expected to have a
    ///   singleton lifestyle.
    /// </summary>
    /// <remarks>
    ///   The constructor is responsible for establishing dependencies with the singleton lifestyle so that they are available
    ///   to all requests. If this isn't the appropriate lifestyle for these dependencies given the specific requirements of the
    ///   application, then the components should be composed separately, instead of relying on the convenience of the <see
    ///   cref="StandardEditorComposer"/>.
    /// </remarks>
    public StandardEditorComposer(ITopicRepository topicRepository, IWebHostEnvironment webHostEnvironment) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate dependencies
      \-----------------------------------------------------------------------------------------------------------------------*/
      Contract.Requires(topicRepository, nameof(topicRepository));
      Contract.Requires(webHostEnvironment, nameof(webHostEnvironment));

      /*------------------------------------------------------------------------------------------------------------------------
      | Initialize Topic Repository
      \-----------------------------------------------------------------------------------------------------------------------*/
      _topicRepository          = topicRepository;
      _webHostEnvironment       = webHostEnvironment;
      _typeLookupService        = new EditorViewModelLookupService();
      _topicMappingService      = new TopicMappingService(_topicRepository, _typeLookupService);

    }