Пример #1
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
            )
              );
        }
Пример #2
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of a <see cref ="OrdersController"/> with necessary dependencies.
 /// </summary>
 /// <returns>A topic controller for loading OnTopic views.</returns>
 public InvoicesController(
   ITopicRepository topicRepository,
   ITopicMappingService topicMappingService
 ) {
   _topicRepository          = topicRepository;
   _topicMappingService      = topicMappingService;
 }
    /*==========================================================================================================================
    | 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
        )
      );

    }
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Initializes a new instance of the <see cref="TopicControllerTest"/> with shared resources.
    /// </summary>
    /// <remarks>
    ///   This uses the <see cref="StubTopicRepository"/> to provide data, and then <see cref="CachedTopicRepository"/> to
    ///   manage the in-memory representation of the data. While this introduces some overhead to the tests, the latter is a
    ///   relatively lightweight façade to any <see cref="ITopicRepository"/>, and prevents the need to duplicate logic for
    ///   crawling the object graph. In addition, it initializes a shared <see cref="Topic"/> reference to use for the various
    ///   tests.
    /// </remarks>
    public TopicControllerTest() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish dependencies
      \-----------------------------------------------------------------------------------------------------------------------*/
      _topicRepository          = new CachedTopicRepository(new StubTopicRepository());
      _topic                    = _topicRepository.Load("Root:Web:Web_0:Web_0_1:Web_0_1_1")!;
      _topicMappingService      = new TopicMappingService(_topicRepository, new TopicViewModelLookupService());

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish view model context
      \-----------------------------------------------------------------------------------------------------------------------*/
      var routes                = new RouteData();

      routes.Values.Add("rootTopic", "Web");
      routes.Values.Add("path", "Web_0/Web_0_1/Web_0_1_1");

      var actionContext         = new ActionContext {
        HttpContext             = new DefaultHttpContext(),
        RouteData               = routes,
        ActionDescriptor        = new ControllerActionDescriptor()
      };
      _context                  = new(actionContext);

    }
Пример #5
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of an <see cref="CoursesController"/> with necessary dependencies.
 /// </summary>
 /// <returns>An <see cref="CoursesController"/> for loading OnTopic views.</returns>
 public CoursesController(
   ITopicRepository topicRepository,
   ITopicMappingService topicMappingService
 ) : base(
   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
                );
        }
Пример #7
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of a <see cref="LessonPagingViewComponent"/> with necessary dependencies.
 /// </summary>
 public LessonPagingViewComponent(
   ITopicRepository topicRepository,
   ITopicMappingService topicMappingService
 ) {
   TopicRepository           = topicRepository;
   TopicMappingService       = topicMappingService;
 }
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of a <see cref="HierarchicalTopicMappingService{T}"/> with necessary dependencies.
 /// </summary>
 /// <returns>A topic controller for loading OnTopic views.</returns>
 public HierarchicalTopicMappingService(
   ITopicRepository topicRepository,
   ITopicMappingService topicMappingService
 ) {
   TopicRepository           = topicRepository;
   _topicMappingService      = topicMappingService;
 }
Пример #9
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);

    }
Пример #10
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of a <see cref="LicensesController"/> with necessary dependencies.
 /// </summary>
 public LicensesController(
   ITopicRepository          topicRepository,
   ITopicMappingService      topicMappingService,
   ITopicExportService       topicExportService
 ) : base(
   topicRepository,
   topicMappingService
 ) {
   _topicExportService       = topicExportService?? throw new ArgumentNullException(nameof(topicExportService));
 }
Пример #11
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of a Topic Controller with necessary dependencies.
 /// </summary>
 /// <returns>A topic controller for loading OnTopic views.</returns>
 public FormsController(
   ITopicRepository topicRepository,
   ITopicMappingService topicMappingService,
   IReverseTopicMappingService reverseTopicMappingService,
   ISmtpService smtpService
 ) : base(
   topicRepository,
   topicMappingService
 ) {
   _topicMappingService      = topicMappingService;
   _reverseMappingService    = reverseTopicMappingService;
   _smptService              = smtpService;
 }
Пример #12
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);

    }
Пример #13
0
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Initializes a new instance of a Topic Controller with necessary dependencies.
    /// </summary>
    /// <returns>A topic controller for loading OnTopic views.</returns>
    public PaymentsController(
      ITopicRepository topicRepository,
      ITopicMappingService topicMappingService,
      IBraintreeConfiguration braintreeConfiguration,
      ISmtpService smtpService
    ) : base(
      topicRepository,
      topicMappingService
    ) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Set values locally
      \-----------------------------------------------------------------------------------------------------------------------*/
      _topicMappingService      = topicMappingService;
      _braintreeConfiguration   = braintreeConfiguration;
      _smtpService              = smtpService;

    }
Пример #14
0
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Initializes a new instance of a Topic Controller with necessary dependencies.
    /// </summary>
    /// <returns>A topic controller for loading OnTopic views.</returns>
    public TopicController(
      ITopicRepository topicRepository,
      ITopicMappingService topicMappingService
     ) {

      /*------------------------------------------------------------------------------------------------------------------------
      | Validate input
      \-----------------------------------------------------------------------------------------------------------------------*/
      Contract.Requires(topicRepository, "A concrete implementation of an ITopicRepository is required.");
      Contract.Requires(topicMappingService, "A concrete implementation of an ITopicMappingService is required.");

      /*------------------------------------------------------------------------------------------------------------------------
      | Set values locally
      \-----------------------------------------------------------------------------------------------------------------------*/
      TopicRepository = topicRepository;
      _topicMappingService = topicMappingService;

    }
Пример #15
0
    /*==========================================================================================================================
    | CONSTRUCTOR
    \-------------------------------------------------------------------------------------------------------------------------*/
    /// <summary>
    ///   Initializes a new instance of the <see cref="TopicControllerTest"/> with shared resources.
    /// </summary>
    /// <remarks>
    ///   This uses the <see cref="StubTopicRepository"/> to provide data, and then <see cref="CachedTopicRepository"/> to
    ///   manage the in-memory representation of the data. While this introduces some overhead to the tests, the latter is a
    ///   relatively lightweight façade to any <see cref="ITopicRepository"/>, and prevents the need to duplicate logic for
    ///   crawling the object graph. In addition, it initializes a shared <see cref="Topic"/> reference to use for the various
    ///   tests.
    /// </remarks>
    public TopicViewComponentTest() {

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish dependencies
      \-----------------------------------------------------------------------------------------------------------------------*/
      _topicRepository          = new CachedTopicRepository(new StubTopicRepository());
      _topic                    = _topicRepository.Load("Root:Web:Web_3:Web_3_0")!;
      _topicMappingService      = new TopicMappingService(_topicRepository, new TopicViewModelLookupService());

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

      /*------------------------------------------------------------------------------------------------------------------------
      | Establish view model context
      \-----------------------------------------------------------------------------------------------------------------------*/
      var routes                = new RouteData();

      routes.Values.Add("rootTopic", "Web");
      routes.Values.Add("path", "Web_3/Web_3_0");

      var viewContext           = new ViewContext() {
        HttpContext             = new DefaultHttpContext(),
        RouteData               = routes
      };
      var viewComponentContext  = new ViewComponentContext() {
        ViewContext             = viewContext
      };

      _context                  = viewComponentContext;

    }
Пример #16
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of the <see cref="TopicMappingServiceTest"/> with shared resources.
 /// </summary>
 /// <remarks>
 ///   This uses the <see cref="StubTopicRepository"/> to provide data, and then <see cref="CachedTopicRepository"/> to
 ///   manage the in-memory representation of the data. While this introduces some overhead to the tests, the latter is a
 ///   relatively lightweight façade to any <see cref="ITopicRepository"/>, and prevents the need to duplicate logic for
 ///   crawling the object graph.
 /// </remarks>
 public TopicMappingServiceTest() {
   _topicRepository = new CachedTopicRepository(new StubTopicRepository());
   _mappingService = new TopicMappingService(new DummyTopicRepository(), new FakeViewModelLookupService());
 }
Пример #17
0
 /*==========================================================================================================================
 | CONSTRUCTOR
 \-------------------------------------------------------------------------------------------------------------------------*/
 /// <summary>
 ///   Initializes a new instance of a <see cref="ReflexiveViewComponent"/> with necessary dependencies.
 /// </summary>
 public ReflexiveViewComponent(ITopicRepository topicRepository, ITopicMappingService topicMappingService) : base() {
   _topicRepository = topicRepository;
   _topicMappingService = topicMappingService;
 }