예제 #1
0
        public static void Install(IServiceCollection serviceCollection, String contactPoint, String keyspace)
        {
            serviceCollection.AddSingleton <Mappings, CassandraMappings>();
            serviceCollection.AddSingleton <ICluster>(provider => Cluster.Builder().AddContactPoint((String)contactPoint).Build());

            //serviceCollection.AddSingleton<IUnitOfWork, CassandraUnitOfWork>();
            serviceCollection.AddSingleton <IUnitOfWork>(provider =>
            {
                var unitOfWork = new CassandraUnitOfWork(provider.GetRequiredService <ICluster>(), provider.GetRequiredService <Mappings>(), keyspace);

                // Map UDTs
                var session = unitOfWork.Session;
                session.UserDefinedTypes.Define(
                    UdtMap.For <CaptureEntity>(),
                    UdtMap.For <L7PduEntity>(),
                    UdtMap.For <IPEndPointEntity>(),
                    UdtMap.For <L7ConversationEntity>()
                    );

                return(unitOfWork);
            });

            serviceCollection.AddSingleton <IRepositoryWriterAsync <CaptureEntity>, UnitOfWork.CassandraRepository.BaseRepository <CaptureEntity> >();
            serviceCollection.AddSingleton <IRepositoryWriterAsync <L7ConversationEntity>, UnitOfWork.CassandraRepository.BaseRepository <L7ConversationEntity> >();
        }
예제 #2
0
        public static void Install(IServiceCollection serviceCollection, String keyspace, params String[] contactPoints)
        {
            serviceCollection.AddSingleton <Mappings, CassandraMappings>();
            serviceCollection.AddSingleton <ICluster>(provider => Cluster.Builder().AddContactPoints(contactPoints).Build());

            serviceCollection.AddSingleton <IUnitOfWork>(provider =>
            {
                var unitOfWork = new CassandraUnitOfWork(provider.GetRequiredService <ICluster>(), provider.GetRequiredService <Mappings>(),
                                                         keyspace);

                // Map UDTs (just UDTs, not entities with their own tables)
                var session = unitOfWork.Session;
                session.UserDefinedTypes.Define(UdtMap.For <L7PduEntity>(), UdtMap.For <IPEndPointEntity>());

                return(unitOfWork);
            });

            serviceCollection.AddSingleton <IRepository <CaptureEntity>, BaseRepository <CaptureEntity> >();
            serviceCollection.AddSingleton <IRepository <L7ConversationEntity>, BaseRepository <L7ConversationEntity> >();
            serviceCollection.AddSingleton <IRepositoryWriterAsync <CaptureEntity> >(x => x.GetService <IRepository <CaptureEntity> >());
            serviceCollection.AddSingleton <IRepositoryReaderAsync <CaptureEntity> >(x => x.GetService <IRepository <CaptureEntity> >());
            serviceCollection.AddSingleton <IRepositoryWriterAsync <L7ConversationEntity> >(
                x => x.GetService <IRepository <L7ConversationEntity> >());
            serviceCollection.AddSingleton <IRepositoryReaderAsync <L7ConversationEntity> >(
                x => x.GetService <IRepository <L7ConversationEntity> >());
        }
예제 #3
0
        public void DisposeWorksCorrectly()
        {
            //Arrange
            var cluster    = Cluster.Builder().AddContactPoint("127.0.0.1").Build();
            var unitOfWork = new CassandraUnitOfWork(cluster, new CassandraEntityMappings());
            var repository = new BaseRepository <Foo>(this._unitOfWork);

            //Act
            repository.Insert(new Foo {
                Id = Guid.NewGuid()
            });
            unitOfWork.SaveChanges();
            unitOfWork.Dispose();

            //Assert
        }
예제 #4
0
        public static void Install(IServiceCollection serviceCollection, String keyspace, params String[] contactPoints)
        {
            serviceCollection.AddSingleton <Mappings, CassandraMappings>();
            serviceCollection.AddSingleton <ICluster>(provider => Cluster.Builder().AddContactPoints(contactPoints).Build());

            serviceCollection.AddSingleton <IUnitOfWork>(provider =>
            {
                var unitOfWork = new CassandraUnitOfWork(provider.GetRequiredService <ICluster>(), provider.GetRequiredService <Mappings>(),
                                                         keyspace);

                // Map UDTs (just UDTs, not entities with their own tables)
                var session = unitOfWork.Session;
                session.UserDefinedTypes.Define(UdtMap.For <L7PduEntity>(),
                                                UdtMap.For <IPEndPointEntity>(),
                                                UdtMap.For <DnsExportEntity.DnsQueryEntity>(),
                                                UdtMap.For <DnsExportEntity.DnsAnswerEntity>());

                return(unitOfWork);
            });

            EntityRepositoriesServiceInstaller.InstallEntityRepositories(serviceCollection, typeof(BaseRepository <>));
        }