예제 #1
0
        public MasterDataDbGenerator(IUnitOfWorkFactory unitOfWorkFactory, IDbContextFactory dbContextFactory)
        {
            _dbContextFactory = dbContextFactory;

            var dateTimeProvider = new DefaultDateTimeProvider();
            var jsonSerializer   = new NewtonsoftJsonSerializer();

            var classifierTreeRepository = new DbClassifierTreeRepository(dbContextFactory);
            var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory);

            var fieldProviderRegistry = new DefaultFieldProviderRegistry();

            fieldProviderRegistry.AddFieldType(typeof(TextField));
            fieldProviderRegistry.AddFieldType(typeof(TextAreaField));

            var dbFieldMetadataRepository = new DbFieldMetadataRepository(dbContextFactory, fieldProviderRegistry, jsonSerializer);
            var dbFieldDataRepository     = new DbFieldDataRepository(dbContextFactory, fieldProviderRegistry);
            var dbFieldMetadataService    = new DbFieldMetadataService(dbContextFactory, dateTimeProvider, jsonSerializer);

            _classifierTypeService           = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository);
            _getClassifierTreeListHandler    = new GetClassifierTreeListHandler(classifierTreeRepository);
            _insertClassifierTreeTypeHandler = new InsertClassifierTreeHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService);
            _insertClassifierTypeHandler     = new InsertClassifierTypeHandler(unitOfWorkFactory, _classifierTypeService, dbFieldMetadataService);
            _insertClassifierGroupHandler    = new InsertClassifierGroupHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService);

            _classifierTypeRegistrator = new DefaultClassifierTypeRegistrator(new NullLogger <DefaultClassifierTypeRegistrator>(),
                                                                              unitOfWorkFactory, _classifierTypeService, dbFieldMetadataService);

            var classifierTypeMetadataService = new ClassifierTypeMetadataService(dbFieldMetadataRepository);
            var classifierTreeService         = new DefaultClassifierTreeService(classifierTreeRepository);
            var dbNumberGenerator             = new DbNumberGenerator(dbContextFactory, null, dateTimeProvider, null);

            var classifierRepositoryFactory = new ClassifierRepositoryFactory(new DbClassifierRepository <Classifier>(
                                                                                  dbContextFactory, _classifierTypeService, classifierTreeService,
                                                                                  classifierTypeMetadataService, dbFieldDataRepository, dbNumberGenerator));

            _insertClassifierHandler      = new InsertClassifierHandler(unitOfWorkFactory, classifierRepositoryFactory);
            _updateClassifierGroupHandler = new UpdateClassifierGroupHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService);
            _deleteClassifierGroupHandler = new DeleteClassifierGroupHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService);
            _insertClassifierLinkHandler  = new InsertClassifierLinkHandler(unitOfWorkFactory, dbContextFactory, _classifierTypeService);
            _getClassifierLinkListHandler = new GetClassifierLinkListHandler(dbContextFactory, _classifierTypeService);
        }
예제 #2
0
        private static INamedServiceFactory <IClassifierRepository> CreateClassifierRepositoryFactory(IDbContextFactory dbContextFactory)
        {
            var classifierTypeRepository = new DbClassifierTypeRepository(dbContextFactory);
            var classifierTypeService    = new DbClassifierTypeService(dbContextFactory, classifierTypeRepository);

            var fieldProviderRegistry = new DefaultFieldProviderRegistry();

            fieldProviderRegistry.AddFieldType(typeof(TextField));
            fieldProviderRegistry.AddFieldType(typeof(TextAreaField));
            var dbFieldDataRepository = new DbFieldDataRepository(dbContextFactory, fieldProviderRegistry);

            var metadataService = new ClassifierTypeMetadataService(new DbFieldMetadataRepository(
                                                                        dbContextFactory, fieldProviderRegistry, new NewtonsoftJsonSerializer()));

            var classifierRepository = new DbClassifierRepository <Classifier>(dbContextFactory,
                                                                               classifierTypeService, null, metadataService, dbFieldDataRepository, null);

            var numeratorRepository = new DbNumeratorRepository(dbContextFactory,
                                                                classifierTypeService, null, metadataService, dbFieldDataRepository, null);

            var documentTypeRepository = new DbDocumentTypeRepository(dbContextFactory,
                                                                      classifierTypeService, null, metadataService, dbFieldDataRepository, null);

            var classifierRepositoryFactoryMock = new Mock <INamedServiceFactory <IClassifierRepository> >();

            classifierRepositoryFactoryMock
            .Setup(x => x.GetNamedOrDefaultService(It.Is <string>(name => name == ClassifierTypeCode.Numerator)))
            .Returns(() => numeratorRepository);
            classifierRepositoryFactoryMock
            .Setup(x => x.GetNamedOrDefaultService(It.Is <string>(name => name == Docs.ClassifierTypeCode.DocumentType)))
            .Returns(() => documentTypeRepository);
            classifierRepositoryFactoryMock
            .Setup(x => x.GetNamedOrDefaultService(It.Is <string>(name => name != ClassifierTypeCode.Numerator && name != Docs.ClassifierTypeCode.DocumentType)))
            .Returns(() => classifierRepository);

            return(classifierRepositoryFactoryMock.Object);
        }