private static async Task <int> InvokeRunAsnyc(
            Options options,
            CancellationToken cancellationToken)
        {
            int toReturn = -1;

            string documentMetadataConnectionString =
                options.DocumentMetadataConnectionString;

            DocumentMetadataAdapterSettingsProvider documentMetadataAdapterSettingsProvider =
                new DocumentMetadataAdapterSettingsProvider(
                    documentMetadataConnectionString);

            string destinationStorageConnectionString =
                options.DestinationStorageConnectionString;
            string destinationStorageFileShareName =
                options.DestinationStorageFileShareName;
            string sourceStorageConnectionString =
                options.SourceStorageConnectionString;
            string sourceStorageFileShareName =
                options.SourceStorageFileShareName;
            DocumentStorageAdapterSettingsProvider documentStorageAdapterSettingsProvider =
                new DocumentStorageAdapterSettingsProvider(
                    destinationStorageConnectionString,
                    destinationStorageFileShareName,
                    sourceStorageConnectionString,
                    sourceStorageFileShareName);

            byte degreeOfParallelism = options.DegreeOfParallelism;
            UnpackRoutineSettingsProvider unpackRoutineSettingsProvider =
                new UnpackRoutineSettingsProvider(degreeOfParallelism);

            using (ServiceProvider serviceProvider = CreateServiceProvider(documentMetadataAdapterSettingsProvider, documentStorageAdapterSettingsProvider, unpackRoutineSettingsProvider))
            {
                IProgram program = serviceProvider.GetService <IProgram>();

                toReturn = await program.RunAsync(options, cancellationToken)
                           .ConfigureAwait(false);
            }

            return(toReturn);
        }
        private static ServiceProvider CreateServiceProvider(
            DocumentMetadataAdapterSettingsProvider documentMetadataAdapterSettingsProvider,
            DocumentStorageAdapterSettingsProvider documentStorageAdapterSettingsProvider,
            UnpackRoutineSettingsProvider unpackRoutineSettingsProvider)
        {
            ServiceProvider toReturn = null;

            IServiceCollection serviceCollection = new ServiceCollection()
                                                   .AddSingleton <IDocumentMetadataAdapterSettingsProvider>(documentMetadataAdapterSettingsProvider)
                                                   .AddSingleton <IDocumentStorageAdapterSettingsProvider>(documentStorageAdapterSettingsProvider)
                                                   .AddSingleton <IUnpackRoutineSettingsProvider>(unpackRoutineSettingsProvider)
                                                   .AddScoped <IDocumentMetadataAdapter, DocumentMetadataAdapter>()
                                                   .AddScoped <IDocumentStorageAdapter, DocumentStorageAdapter>()
                                                   .AddSingleton <ILoggerWrapper, LoggerWrapper>()
                                                   .AddSingleton <IUnpackRoutine, UnpackRoutine>()
                                                   .AddSingleton <IProgram, Program>();

            toReturn = serviceCollection.BuildServiceProvider();

            return(toReturn);
        }