/*========================================================================================================================== | 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> /// 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 ); }
/*========================================================================================================================== | 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="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); }
protected void Application_Start(object sender, EventArgs e) { /*------------------------------------------------------------------------------------------------------------------------ | CONFIGURE REPOSITORY \-----------------------------------------------------------------------------------------------------------------------*/ var connectionString = ConfigurationManager.ConnectionStrings["OnTopic"].ConnectionString; var sqlTopicRepository = new SqlTopicRepository(connectionString); var topicRepository = new CachedTopicRepository(sqlTopicRepository); TopicRepository.DataProvider = topicRepository; /*------------------------------------------------------------------------------------------------------------------------ | REGISTER ROUTES \-----------------------------------------------------------------------------------------------------------------------*/ RegisterRoutes(RouteTable.Routes); }