internal TorrentDownload Add(Metainfo metainfo, ITracker tracker, IFileHandler fileHandler)
        {
            var dataHandler = new PieceCheckerHandler(new BlockDataHandler(fileHandler, metainfo));
            var bitTorrentApplicationProtocol = new BitTorrentApplicationProtocol <BitTorrentPeerInitiator.IContext>(LocalPeerId, metainfo, peerInitiator, m => new QueueingMessageHandler(mainLoop, m), moduleManager, dataHandler);
            var downloadManager = new TorrentDownloadManager(LocalPeerId,
                                                             mainLoop,
                                                             bitTorrentApplicationProtocol,
                                                             tracker,
                                                             metainfo);

            var download = new TorrentDownload(downloadManager);

            downloads.Add(metainfo.InfoHash, download);
            return(download);
        }
        internal TorrentDownload Add(Metainfo metainfo, ITracker tracker, IFileHandler fileHandler)
        {
            // Create a new scope for this download
            var scope       = _services.CreateScope();
            var dataHandler = ActivatorUtilities.CreateInstance <PieceCheckerHandler>(scope.ServiceProvider, new BlockDataHandler(fileHandler, metainfo));
            var applicationProtocolFactory = scope.ServiceProvider.GetRequiredService <IApplicationProtocolFactory>();
            var applicationProtocol        = applicationProtocolFactory.Create(metainfo, dataHandler);
            var pipelineRunner             = ActivatorUtilities.CreateInstance <PipelineRunner>(scope.ServiceProvider, applicationProtocol, tracker);

            _peerInitiator.OnApplicationProtocolAdded(pipelineRunner.ApplicationProtocol);

            var download = new TorrentDownload(pipelineRunner);

            _downloads.Add(metainfo.InfoHash, download);
            return(download);
        }