Documentation Coverage Report
Current view: top level - Ninject/Cqrs.Ninject/Configuration - SimplifiedNinjectStartUp.cs Hit Total Coverage
Version: 2.2 Artefacts: 6 6 100.0 %
Date: 2018-08-07 15:04:50

          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 System;
      10             : using Cqrs.Authentication;
      11             : using Cqrs.Configuration;
      12             : using Ninject;
      13             : using Ninject.Modules;
      14             : 
      15             : namespace Cqrs.Ninject.Configuration
      16             : {
      17             :         /// <summary>
      18             :         /// A start-up class.
      19             :         /// </summary>
      20             :         /// <typeparam name="THostModule">The base <see cref="INinjectModule"/> that is loaded first.</typeparam>
      21             :         public class SimplifiedNinjectStartUp<THostModule>
      22             :                 where THostModule : INinjectModule, new()
      23           1 :         {
      24             :                 /// <summary>
      25             :                 /// Instantiates a new instance of <see cref="SimplifiedNinjectStartUp{THostModule}"/>
      26             :                 /// </summary>
      27           1 :                 public SimplifiedNinjectStartUp(IConfigurationManager configurationManager)
      28             :                 {
      29             :                         ConfigurationManager = configurationManager;
      30             :                 }
      31             : 
      32             :                 /// <summary>
      33             :                 /// The <see cref="IConfigurationManager"/> that will be used to resolve configuration settings in <see cref="CreateKernel"/>.
      34             :                 /// It is not used elsewhere.
      35             :                 /// </summary>
      36             :                 protected IConfigurationManager ConfigurationManager { get; private set; }
      37             : 
      38             :                 /// <summary>
      39             :                 /// Creates the kernel that will manage your application.
      40             :                 /// </summary>
      41             :                 /// <returns>The created kernel.</returns>
      42           1 :                 public virtual IKernel CreateKernel()
      43             :                 {
      44             :                         NinjectDependencyResolver.ModulesToLoad.Insert(0, new THostModule());
      45             : 
      46             :                         string authenticationType;
      47             :                         if (!ConfigurationManager.TryGetSetting("Cqrs.AuthenticationTokenType", out authenticationType))
      48             :                                 authenticationType = "Guid";
      49             : 
      50             :                         if (authenticationType.ToLowerInvariant() == "int" || authenticationType.ToLowerInvariant() == "integer")
      51             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<int, DefaultAuthenticationTokenHelper>(true, false));
      52             :                         else if (authenticationType.ToLowerInvariant() == "guid")
      53             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<Guid, DefaultAuthenticationTokenHelper>(true, false));
      54             :                         else if (authenticationType.ToLowerInvariant() == "string" || authenticationType.ToLowerInvariant() == "text")
      55             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<string, DefaultAuthenticationTokenHelper>(true, false));
      56             : 
      57             :                         else if (authenticationType == "SingleSignOnToken")
      58             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<SingleSignOnToken, DefaultAuthenticationTokenHelper>(true, false));
      59             :                         else if (authenticationType == "SingleSignOnTokenWithUserRsn")
      60             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<SingleSignOnTokenWithUserRsn, DefaultAuthenticationTokenHelper>(true, false));
      61             :                         else if (authenticationType == "SingleSignOnTokenWithCompanyRsn")
      62             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<SingleSignOnTokenWithCompanyRsn, DefaultAuthenticationTokenHelper>(true, false));
      63             :                         else if (authenticationType == "SingleSignOnTokenWithUserRsnAndCompanyRsn")
      64             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<SingleSignOnTokenWithUserRsnAndCompanyRsn, DefaultAuthenticationTokenHelper>(true, false));
      65             : 
      66             :                         else if (authenticationType == "ISingleSignOnToken")
      67             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<ISingleSignOnToken, AuthenticationTokenHelper>(true, false));
      68             :                         else if (authenticationType == "ISingleSignOnTokenWithUserRsn")
      69             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<ISingleSignOnTokenWithUserRsn, AuthenticationTokenHelper>(true, false));
      70             :                         else if (authenticationType == "ISingleSignOnTokenWithCompanyRsn")
      71             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<ISingleSignOnTokenWithCompanyRsn, AuthenticationTokenHelper>(true, false));
      72             :                         else if (authenticationType == "ISingleSignOnTokenWithUserRsnAndCompanyRsn")
      73             :                                 NinjectDependencyResolver.ModulesToLoad.Insert(1, new CqrsModule<ISingleSignOnTokenWithUserRsnAndCompanyRsn, AuthenticationTokenHelper>(true, false));
      74             : 
      75             :                         AddSupplementryModules();
      76             : 
      77             :                         StandardKernel kernel = CreateNinjectKernel();
      78             :                         StartResolver(kernel);
      79             : 
      80             :                         return kernel;
      81             :                 }
      82             : 
      83             :                 /// <summary>
      84             :                 /// When overridden allows for the addition of any additional <see cref="INinjectModule">modules</see> required.
      85             :                 /// </summary>
      86           1 :                 protected virtual void AddSupplementryModules()
      87             :                 {
      88             :                 }
      89             : 
      90             :                 /// <summary>
      91             :                 /// Create a new <see cref="StandardKernel"/>
      92             :                 /// </summary>
      93           1 :                 protected virtual StandardKernel CreateNinjectKernel()
      94             :                 {
      95             :                         return new StandardKernel();
      96             :                 }
      97             : 
      98             :                 /// <summary>
      99             :                 /// Calls <see cref="NinjectDependencyResolver.Start"/>
     100             :                 /// </summary>
     101           1 :                 protected virtual void StartResolver(IKernel kernel)
     102             :                 {
     103             :                         NinjectDependencyResolver.Start(kernel, true);
     104             :                 }
     105             :         }
     106             : }

Generated by: LCOV version 1.12