コード例 #1
0
        public void TestInitialize()
        {
            NinjectDependencyResolver.ModulesToLoad.Clear();

            // Core Module
            NinjectDependencyResolver.ModulesToLoad.Add(new CqrsModule <ISingleSignOnToken, SingleSignOnTokenValueHelper>());
            // Event Store Module
            NinjectDependencyResolver.ModulesToLoad.Add(new InProcessEventStoreModule <ISingleSignOnToken>());
            // Command Bus Module
            NinjectDependencyResolver.ModulesToLoad.Add(new InProcessCommandBusModule <ISingleSignOnToken>());
            // Event Bus Module
            NinjectDependencyResolver.ModulesToLoad.Add(new InProcessEventBusModule <ISingleSignOnToken>());
            // Domain Core Module
            NinjectDependencyResolver.ModulesToLoad.Add(new DomainCoreModule());
            NinjectDependencyResolver.Start();

            var corrolationIdHelper = NinjectDependencyResolver.Current.Resolve <ICorrolationIdHelper>();

            corrolationIdHelper.SetCorrolationId(Guid.NewGuid());

            var authenticationTokenHelper = NinjectDependencyResolver.Current.Resolve <IAuthenticationTokenHelper <ISingleSignOnToken> >();
            var singleSignOnTokenFactory  = NinjectDependencyResolver.Current.Resolve <ISingleSignOnTokenFactory>();

            authenticationTokenHelper.SetAuthenticationToken(singleSignOnTokenFactory.CreateNew());
        }
コード例 #2
0
        /// <summary>
        /// Starts the <see cref="AkkaNinjectDependencyResolver"/>
        /// </summary>
        /// <remarks>
        /// This exists so the static constructor can be triggered.
        /// </remarks>
        public new static void Start(IKernel kernel = null, bool prepareProvidedKernel = false)
        {
            // Create the ActorSystem and Dependency Resolver
            ActorSystem system = ActorSystem.Create("Cqrs");

            Func <IKernel, NinjectDependencyResolver> originalDependencyResolverCreator = DependencyResolverCreator;
            Func <IKernel, NinjectDependencyResolver> dependencyResolverCreator         = container => new AkkaNinjectDependencyResolver(container, system);

            if (originalDependencyResolverCreator == null)
            {
                DependencyResolverCreator = dependencyResolverCreator;
            }
            else
            {
                DependencyResolverCreator = container =>
                {
                    originalDependencyResolverCreator(container);
                    return(dependencyResolverCreator(container));
                }
            };

            NinjectDependencyResolver.Start(kernel, prepareProvidedKernel);

            // Setup an actor that will handle deadletter type messages
            var deadletterWatchMonitorProps = Props.Create(() => new DeadletterToLoggerProxy(Current.Resolve <ILogger>()));
            var deadletterWatchActorRef     = system.ActorOf(deadletterWatchMonitorProps, "DeadLetterMonitoringActor");

            // subscribe to the event stream for messages of type "DeadLetter"
            system.EventStream.Subscribe(deadletterWatchActorRef, typeof(DeadLetter));
        }
コード例 #3
0
ファイル: SnapshotTests.cs プロジェクト: quanliang2000/CQRS
        public void Should_load_events()
        {
            // Arrange
            NinjectDependencyResolver.ModulesToLoad.Add(new CqrsModule <int, DefaultAuthenticationTokenHelper>());
            NinjectDependencyResolver.ModulesToLoad.Add(new SimplifiedSqlModule <int>());
            NinjectDependencyResolver.ModulesToLoad.Add(new InProcessEventBusModule <int>());
            NinjectDependencyResolver.Start();
            var unitOfWork = new UnitOfWork <int>(DependencyResolver.Current.Resolve <ISnapshotAggregateRepository <int> >());
            var aggregate  = DependencyResolver.Current.Resolve <IAggregateFactory>().Create <TestAggregate>(Guid.NewGuid());

            unitOfWork.Add(aggregate);
            int count = 0;

            do
            {
                aggregate.GenerateRandomNumber();
                if (count % 10 == 0)
                {
                    unitOfWork.Commit();
                    unitOfWork.Add(aggregate);
                }
            } while (count++ <= 20);
            unitOfWork.Commit();

            // Act
            var aggregate2 = unitOfWork.Get <TestAggregate>(aggregate.Rsn);

            // Assert
            Assert.AreEqual(22, aggregate2.Version);
            Assert.AreEqual(aggregate.CurrentRandomNumber, aggregate2.CurrentRandomNumber);
        }
コード例 #4
0
ファイル: DomainConfiguration.cs プロジェクト: anhzin/CQRS-1
        public void Start()
        {
            NinjectDependencyResolver.ModulesToLoad.Add(new THostModule());
            NinjectDependencyResolver.ModulesToLoad.Add(new CqrsModule <ISingleSignOnToken, SingleSignOnTokenValueHelper>());

            NinjectDependencyResolver.Start();
        }
コード例 #5
0
        /// <summary>
        /// Starts the <see cref="AkkaNinjectDependencyResolver"/>
        /// </summary>
        /// <remarks>
        /// this exists to the static constructor can be triggered.
        /// </remarks>
        public new static void Start(IKernel kernel = null, bool prepareProvidedKernel = false)
        {
            // Create the ActorSystem and Dependency Resolver
            ActorSystem system = ActorSystem.Create("Cqrs");

            DependencyResolverCreator = container => new AkkaNinjectDependencyResolver(container, system);
            NinjectDependencyResolver.Start(kernel, prepareProvidedKernel);
        }
コード例 #6
0
        protected override void StartResolver()
        {
            // NinjectDependencyResolver.Start();
            var kernel = new StandardKernel();

            // This is only done so the follow Wcf safe method can be called. Otherwise use the commented out line above.
            NinjectDependencyResolver.Start(kernel, true);
            BaseNinjectServiceHostFactory.SetKernel(kernel);
        }
コード例 #7
0
        public void Should_load_events()
        {
            // Arrange
            TestMongoDbSnapshotStoreConnectionStringFactory.DatabaseName = string.Format("Test-{0}", new Random().Next(0, 9999));
            NinjectDependencyResolver.ModulesToLoad.Add(new CqrsModule <int, DefaultAuthenticationTokenHelper>());
            NinjectDependencyResolver.ModulesToLoad.Add(new InProcessEventBusModule <int>());
            NinjectDependencyResolver.ModulesToLoad.Add(new TestMongoDbModule <int>());
            NinjectDependencyResolver.Start();
            var unitOfWork = new UnitOfWork <int>(DependencyResolver.Current.Resolve <ISnapshotAggregateRepository <int> >());
            var aggregate  = DependencyResolver.Current.Resolve <IAggregateFactory>().Create <TestAggregate>(Guid.NewGuid());

            unitOfWork.Add(aggregate);
            try
            {
                int count = 0;
                do
                {
                    aggregate.GenerateRandomNumber();
                    if (count % 10 == 0)
                    {
                        unitOfWork.Commit();
                        unitOfWork.Add(aggregate);
                    }
                } while (count++ <= 20);
                unitOfWork.Commit();

                // Act
                var aggregate2 = unitOfWork.Get <TestAggregate>(aggregate.Rsn);

                // Assert
                Assert.AreEqual(22, aggregate2.Version);
                Assert.AreEqual(aggregate.CurrentRandomNumber, aggregate2.CurrentRandomNumber);
            }
            finally
            {
                // Clean-up
                TestMongoDataStoreConnectionStringFactory.DatabaseName = TestMongoDbSnapshotStoreConnectionStringFactory.DatabaseName;
                var factory = new TestMongoDbDataStoreFactory(DependencyResolver.Current.Resolve <ILogger>(), new TestMongoDataStoreConnectionStringFactory());
                IMongoCollection <TestEvent> collection = factory.GetTestEventCollection();
                collection.Database.Client.DropDatabase(TestMongoDataStoreConnectionStringFactory.DatabaseName);
            }
        }
コード例 #8
0
        /// <summary>
        /// Starts the <see cref="AkkaNinjectDependencyResolver"/>
        /// </summary>
        /// <remarks>
        /// This exists so the static constructor can be triggered.
        /// </remarks>
        public new static void Start(IKernel kernel = null, bool prepareProvidedKernel = false)
        {
            // Create the ActorSystem and Dependency Resolver
            ActorSystem system = ActorSystem.Create("Cqrs");

            Func <IKernel, NinjectDependencyResolver> originalDependencyResolverCreator = DependencyResolverCreator;
            Func <IKernel, NinjectDependencyResolver> dependencyResolverCreator         = container => new AkkaNinjectDependencyResolver(container, system);

            if (originalDependencyResolverCreator == null)
            {
                DependencyResolverCreator = dependencyResolverCreator;
            }
            else
            {
                DependencyResolverCreator = container =>
                {
                    originalDependencyResolverCreator(container);
                    return(dependencyResolverCreator(container));
                }
            };

            NinjectDependencyResolver.Start(kernel, prepareProvidedKernel);
        }
コード例 #9
0
ファイル: DomainConfiguration.cs プロジェクト: jdiss/CQRS
 protected virtual void StartResolver()
 {
     NinjectDependencyResolver.Start();
 }