Documentation Coverage Report
Current view: top level - Ninject/Azure/Cqrs.Ninject.Azure.Wcf/Configuration - WebHostModule.cs Hit Total Coverage
Version: 2.2 Artefacts: 7 7 100.0 %
Date: 2017-09-22

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using cdmdotnet.Logging;
      10             : using cdmdotnet.Logging.Azure.ApplicationInsights;
      11             : using cdmdotnet.Logging.Azure.Configuration;
      12             : using cdmdotnet.Logging.Configuration;
      13             : using cdmdotnet.StateManagement;
      14             : using Cqrs.Azure.ConfigurationManager;
      15             : using Cqrs.Configuration;
      16             : using Ninject;
      17             : using Ninject.Modules;
      18             : using Ninject.Web.Common;
      19             : using System;
      20             : using System.Web;
      21             : using cdmdotnet.StateManagement.Web;
      22             : using Cqrs.Authentication;
      23             : using Cqrs.Ninject.Configuration;
      24             : using Cqrs.Services;
      25             : 
      26             : namespace Cqrs.Ninject.Azure.Wcf.Configuration
      27             : {
      28             :         /// <summary>
      29             :         /// The core <see cref="INinjectModule"/> for use defining base level requirements.
      30             :         /// </summary>
      31             :         public class WebHostModule : ResolvableModule
      32           1 :         {
      33             :                 #region Overrides of NinjectModule
      34             : 
      35             :                 /// <summary>
      36             :                 /// Loads the module into the kernel.
      37             :                 /// </summary>
      38           1 :                 public override void Load()
      39             :                 {
      40             :                         RegisterBasicHelpers();
      41             :                         RegisterAzureConfigurations();
      42             :                         RegisterBasicSerives();
      43             :                         RegisterWebBit();
      44             :                 }
      45             : 
      46             :                 #endregion
      47             : 
      48             :                 /// <summary>
      49             :                 /// Register the all Azure configurations
      50             :                 /// </summary>
      51           1 :                 protected virtual void RegisterAzureConfigurations()
      52             :                 {
      53             :                         Bind<ILoggerSettings>()
      54             :                                 .To<AzureLoggerSettingsConfiguration>()
      55             :                                 .InSingletonScope();
      56             : 
      57             :                         Bind<IConfigurationManager>()
      58             :                                 .To<CloudConfigurationManager>()
      59             :                                 .InSingletonScope();
      60             :                 }
      61             : 
      62             :                 /// <summary>
      63             :                 /// Registers the basic helpers required.
      64             :                 /// </summary>
      65           1 :                 protected virtual void RegisterBasicHelpers()
      66             :                 {
      67             :                         RegisterContextItemCollectionFactory();
      68             : 
      69             :                         Bind<ITelemetryHelper>()
      70             :                                 .To<TelemetryHelper>()
      71             :                                 .InSingletonScope();
      72             :                 }
      73             :                 /// <summary>
      74             :                 /// Registers the <see cref="IContextItemCollectionFactory"/> required.
      75             :                 /// </summary>
      76           1 :                 protected virtual void RegisterContextItemCollectionFactory()
      77             :                 {
      78             :                         // We use console state as, even though a webjob runs in an azure website, it's technically loaded via something call the 'WindowsScriptHost', which is not web and IIS based so it's threading model is very different and more console based.
      79             :                         Bind<IContextItemCollectionFactory>()
      80             :                                 .To<WebContextItemCollectionFactory>()
      81             :                                 .InSingletonScope();
      82             :                 }
      83             : 
      84             :                 /// <summary>
      85             :                 /// Registers the basic services required.
      86             :                 /// </summary>
      87           1 :                 protected virtual void RegisterBasicSerives()
      88             :                 {
      89             :                         string authenticationType;
      90             :                         if (!Resolve<IConfigurationManager>().TryGetSetting("Cqrs.AuthenticationTokenType", out authenticationType))
      91             :                                 authenticationType = "Guid";
      92             : 
      93             :                         if (authenticationType.ToLowerInvariant() == "int" || authenticationType.ToLowerInvariant() == "integer")
      94             :                                 Bind<IUnitOfWorkService>()
      95             :                                         .To<UnitOfWorkService<int>>()
      96             :                                         .InThreadScope();
      97             :                         else if (authenticationType.ToLowerInvariant() == "guid")
      98             :                                 Bind<IUnitOfWorkService>()
      99             :                                         .To<UnitOfWorkService<Guid>>()
     100             :                                         .InThreadScope();
     101             :                         else if (authenticationType.ToLowerInvariant() == "string" || authenticationType.ToLowerInvariant() == "text")
     102             :                                 Bind<IUnitOfWorkService>()
     103             :                                         .To<UnitOfWorkService<string>>()
     104             :                                         .InThreadScope();
     105             : 
     106             :                         else if (authenticationType == "SingleSignOnToken")
     107             :                                 Bind<IUnitOfWorkService>()
     108             :                                         .To<UnitOfWorkService<SingleSignOnToken>>()
     109             :                                         .InThreadScope();
     110             :                         else if (authenticationType == "SingleSignOnTokenWithUserRsn")
     111             :                                 Bind<IUnitOfWorkService>()
     112             :                                         .To<UnitOfWorkService<SingleSignOnTokenWithUserRsn>>()
     113             :                                         .InThreadScope();
     114             :                         else if (authenticationType == "SingleSignOnTokenWithCompanyRsn")
     115             :                                 Bind<IUnitOfWorkService>()
     116             :                                         .To<UnitOfWorkService<SingleSignOnTokenWithCompanyRsn>>()
     117             :                                         .InThreadScope();
     118             :                         else if (authenticationType == "SingleSignOnTokenWithUserRsnAndCompanyRsn")
     119             :                                 Bind<IUnitOfWorkService>()
     120             :                                         .To<UnitOfWorkService<SingleSignOnTokenWithUserRsnAndCompanyRsn>>()
     121             :                                         .InThreadScope();
     122             : 
     123             :                         else if (authenticationType == "ISingleSignOnToken")
     124             :                                 Bind<IUnitOfWorkService>()
     125             :                                         .To<UnitOfWorkService<ISingleSignOnToken>>()
     126             :                                         .InThreadScope();
     127             :                         else if (authenticationType == "ISingleSignOnTokenWithUserRsn")
     128             :                                 Bind<IUnitOfWorkService>()
     129             :                                         .To<UnitOfWorkService<ISingleSignOnTokenWithUserRsn>>()
     130             :                                         .InThreadScope();
     131             :                         else if (authenticationType == "ISingleSignOnTokenWithCompanyRsn")
     132             :                                 Bind<IUnitOfWorkService>()
     133             :                                         .To<UnitOfWorkService<ISingleSignOnTokenWithCompanyRsn>>()
     134             :                                         .InThreadScope();
     135             :                         else if (authenticationType == "ISingleSignOnTokenWithUserRsnAndCompanyRsn")
     136             :                                 Bind<IUnitOfWorkService>()
     137             :                                         .To<UnitOfWorkService<ISingleSignOnTokenWithUserRsnAndCompanyRsn>>()
     138             :                                         .InThreadScope();
     139             :                 }
     140             : 
     141             :                 /// <summary>
     142             :                 /// Registers some things Ninject likes.
     143             :                 /// </summary>
     144           1 :                 protected virtual void RegisterWebBit()
     145             :                 {
     146             :                         Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
     147             :                         Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
     148             :                 }
     149             :         }
     150             : }

Generated by: LCOV version 1.10