private static void InitializeDependencies()
        {
            Trace.Listeners.Add(new TextWriterTraceListener(LOG_FILE));
            var configuration
                = (DocumentsJoinerConfigurationSection)ConfigurationManager.GetSection(SERVICE_CONFIGURATION_SECTION);
            var detector = new ZXingBarcodeDetector();
            Func <DocumentsController, SortedDictionary <int, IDocumentHandler> > handlersChainFactory = ctrl =>
            {
                var sorted = new SortedDictionary <int, IDocumentHandler>
                {
                    { 1, new DocumentValidator(configuration.BrokenFilesDirectory) },
                    { 2, new BarCodeHandler(detector, ctrl) },
                    { 3, new ImageHandler(ctrl) },
                };

                return(sorted);
            };
            var fileReader        = new WaitForFile(configuration.AttemptsToOpenFile, configuration.OpeningFilePeriodMs);
            var exceptionsHandler = new ErrorHandler(configuration.BrokenFilesDirectory);
            Func <DocumentsController> controllersFactory
                = () => new DocumentsController(
                      handlersChainFactory,
                      exceptionsHandler,
                      fileReader,
                      configuration.Timeout);
            Func <CancellationToken, IDocumentsJoiner> joinerFactory
                = token => new PdfSharpDocumentsJoiner(token, fileReader);

            documentsJoinerWorker = new DocumentsJoinerWorker(configuration, controllersFactory, joinerFactory);
        }
        public ServiceFacade()
        {
            var configuration = (DocumentsJoinerConfigurationSection)ConfigurationManager
                                .GetSection(ConfigurationContext.SERVICE_CONFIGURATION_SECTION);
            var detector = new ZXingBarcodeDetector();
            Func <DocumentsController, SortedDictionary <int, IDocumentHandler> > handlersChainFactory = ctrl =>
            {
                var sorted = new SortedDictionary <int, IDocumentHandler>
                {
                    { 1, new DocumentValidator(configuration.BrokenFilesDirectory) },
                    { 2, new BarCodeHandler(detector, ctrl) },
                    { 3, new ImageHandler(ctrl) },
                };

                return(sorted);
            };
            var fileReader        = new WaitForFile(configuration.AttemptsToOpenFile, configuration.OpeningFilePeriodMs);
            var exceptionsHandler = new ErrorHandler(configuration.BrokenFilesDirectory);
            Func <DocumentsController> controllersFactory =
                () => new DocumentsController(handlersChainFactory, exceptionsHandler, fileReader);
            Func <CancellationToken, IDocumentsJoiner> joinerFactory
                = token => new PdfSharpDocumentsJoiner(token, fileReader);
            var queue = new ChunkedQueue();

            documentsJoinerWorker = new DocumentsJoinerWorker(
                configuration,
                controllersFactory,
                joinerFactory,
                queue);

            var observables = new[] { documentsJoinerWorker };
            var statusQueue = new StatusMessagesProducer();

            documentsJoinerStatusObserverWorker = new DocumentsJoinerStatusObserverWorker(observables, statusQueue);

            var commandsQueue = new CommandsSubscriber();

            commandsObserver = new CommandsObserver(commandsQueue, documentsJoinerStatusObserverWorker);
        }