Documentation Coverage Report
Current view: top level - Ninject/Cqrs.Ninject/Configuration - InProcessCommandBusModule.cs Hit Total Coverage
Version: 2.2 Artefacts: 5 5 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 System;
      10             : using System.Linq;
      11             : using Cqrs.Bus;
      12             : using Cqrs.Commands;
      13             : using Ninject;
      14             : using Ninject.Modules;
      15             : 
      16             : namespace Cqrs.Ninject.Configuration
      17             : {
      18             :         /// <summary>
      19             :         /// A <see cref="INinjectModule"/> that configures the <see cref="InProcessBus{TAuthenticationToken}"/> as a <see cref="ICommandPublisher{TAuthenticationToken}"/> and <see cref="ICommandReceiver"/>.
      20             :         /// </summary>
      21             :         /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of the authentication token.</typeparam>
      22             :         public class InProcessCommandBusModule<TAuthenticationToken> : ResolvableModule
      23           1 :         {
      24             :                 #region Overrides of NinjectModule
      25             : 
      26             :                 /// <summary>
      27             :                 /// Loads the module into the kernel.
      28             :                 /// </summary>
      29           1 :                 public override void Load()
      30             :                 {
      31             :                         RegisterFactories();
      32             :                         RegisterServices();
      33             :                         RegisterCqrsRequirements();
      34             :                 }
      35             : 
      36             :                 #endregion
      37             : 
      38             :                 /// <summary>
      39             :                 /// Register the all factories
      40             :                 /// </summary>
      41           1 :                 public virtual void RegisterFactories()
      42             :                 {
      43             :                 }
      44             : 
      45             :                 /// <summary>
      46             :                 /// Register the all services
      47             :                 /// </summary>
      48           1 :                 public virtual void RegisterServices()
      49             :                 {
      50             :                 }
      51             : 
      52             : #pragma warning disable 618
      53             :                 /// <summary>
      54             :                 /// Register the <see cref="ICommandPublisher{TAuthenticationToken}"/>, <see cref="IPublishAndWaitCommandPublisher{TAuthenticationToken}"/>, <see cref="ICommandReceiver{TAuthenticationToken}"/> and <see cref="ICommandHandlerRegistrar"/>
      55             :                 /// Register (for backwards compatibility) <see cref="ICommandSender{TAuthenticationToken}"/>
      56             :                 /// </summary>
      57             : #pragma warning restore 618
      58           1 :                 public virtual void RegisterCqrsRequirements()
      59             :                 {
      60             :                         bool isInProcessBusBound = Kernel.GetBindings(typeof(InProcessBus<TAuthenticationToken>)).Any();
      61             :                         InProcessBus<TAuthenticationToken> inProcessBus;
      62             :                         if (!isInProcessBusBound)
      63             :                         {
      64             :                                 inProcessBus = Kernel.Get<InProcessBus<TAuthenticationToken>>();
      65             :                                 Bind<InProcessBus<TAuthenticationToken>>()
      66             :                                         .ToConstant(inProcessBus)
      67             :                                         .InSingletonScope();
      68             :                         }
      69             :                         else
      70             :                                 inProcessBus = Kernel.Get<InProcessBus<TAuthenticationToken>>();
      71             : 
      72             :                         Bind<ICommandPublisher<TAuthenticationToken>>()
      73             :                                 .ToConstant(inProcessBus)
      74             :                                 .InSingletonScope();
      75             : 
      76             :                         Bind<IPublishAndWaitCommandPublisher<TAuthenticationToken>>()
      77             :                                 .ToConstant(inProcessBus)
      78             :                                 .InSingletonScope();
      79             : 
      80             :                         Bind<ICommandReceiver<TAuthenticationToken>>()
      81             :                                 .ToConstant(inProcessBus)
      82             :                                 .InSingletonScope();
      83             : 
      84             :                         bool isHandlerRegistrationBound = Kernel.GetBindings(typeof(ICommandHandlerRegistrar)).Any();
      85             :                         if (!isHandlerRegistrationBound)
      86             :                         {
      87             :                                 Bind<ICommandHandlerRegistrar>()
      88             :                                         .ToConstant(inProcessBus)
      89             :                                         .InSingletonScope();
      90             :                         }
      91             :                 }
      92             :         }
      93             : }

Generated by: LCOV version 1.10