From a85d1a5ba9b9aa02fc53db008426712394aa9f48 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 25 Jul 2022 21:11:50 -0500 Subject: extract IUploadService, prep for DbContext --- src/slskd/Program.cs | 2 ++ src/slskd/Transfers/TransferService.cs | 21 +--------------- src/slskd/Transfers/Uploads/IUploadService.cs | 35 +++++++++++++++++++++++++++ src/slskd/Transfers/Uploads/UploadService.cs | 33 +++++++++++++------------ 4 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 src/slskd/Transfers/Uploads/IUploadService.cs (limited to 'src') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 1d845ab1..ac5bf99b 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -61,6 +61,7 @@ namespace slskd using slskd.Shares; using slskd.Transfers; using slskd.Transfers.Downloads; + using slskd.Transfers.Uploads; using slskd.Users; using slskd.Validation; using Soulseek; @@ -465,6 +466,7 @@ namespace slskd services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/slskd/Transfers/TransferService.cs b/src/slskd/Transfers/TransferService.cs index 253dc318..20b9b8e3 100644 --- a/src/slskd/Transfers/TransferService.cs +++ b/src/slskd/Transfers/TransferService.cs @@ -15,13 +15,10 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // -using Microsoft.Extensions.Options; - namespace slskd.Transfers { using slskd.Transfers.Downloads; using slskd.Transfers.Uploads; - using slskd.Users; /// /// Manages transfers. @@ -47,24 +44,11 @@ namespace slskd.Transfers /// /// Initializes a new instance of the class. /// - /// The UserService instance to use. - /// The OptionsMonitor instance to use. - /// The optional UploadService instance to use. public TransferService( - IUserService userService, - IOptionsMonitor optionsMonitor, IUploadService uploadService = null, IDownloadService downloadService = null) { - Users = userService; - OptionsMonitor = optionsMonitor; - - Uploads = uploadService ?? new UploadService() - { - Governor = new UploadGovernor(userService: Users, optionsMonitor: OptionsMonitor), - Queue = new UploadQueue(userService: Users, optionsMonitor: OptionsMonitor), - }; - + Uploads = uploadService; Downloads = downloadService; } @@ -77,8 +61,5 @@ namespace slskd.Transfers /// Gets the download service. /// public IDownloadService Downloads { get; init; } - - private IOptionsMonitor OptionsMonitor { get; init; } - private IUserService Users { get; init; } } } \ No newline at end of file diff --git a/src/slskd/Transfers/Uploads/IUploadService.cs b/src/slskd/Transfers/Uploads/IUploadService.cs new file mode 100644 index 00000000..71fc6067 --- /dev/null +++ b/src/slskd/Transfers/Uploads/IUploadService.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) slskd Team. All rights reserved. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published +// by the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see https://www.gnu.org/licenses/. +// + +namespace slskd.Transfers.Uploads +{ + /// + /// Manages uploads. + /// + public interface IUploadService + { + /// + /// Gets the upload governor. + /// + IUploadGovernor Governor { get; } + + /// + /// Gets the upload queue. + /// + IUploadQueue Queue { get; } + } +} \ No newline at end of file diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs index f88e80a8..10e82d7f 100644 --- a/src/slskd/Transfers/Uploads/UploadService.cs +++ b/src/slskd/Transfers/Uploads/UploadService.cs @@ -15,29 +15,32 @@ // along with this program. If not, see https://www.gnu.org/licenses/. // + +using Microsoft.Extensions.Options; + namespace slskd.Transfers.Uploads { - /// - /// Manages uploads. - /// - public interface IUploadService - { - /// - /// Gets the upload governor. - /// - IUploadGovernor Governor { get; } - - /// - /// Gets the upload queue. - /// - IUploadQueue Queue { get; } - } + using Microsoft.EntityFrameworkCore; + using slskd.Users; /// /// Manages uploads. /// public class UploadService : IUploadService { + public UploadService( + IUserService userService, + IOptionsMonitor optionsMonitor, + IDbContextFactory contextFactory) + { + ContextFactory = contextFactory; + + Governor = new UploadGovernor(userService, optionsMonitor); + Queue = new UploadQueue(userService, optionsMonitor); + } + + private IDbContextFactory ContextFactory { get; } + /// /// Gets the upload governor. /// -- cgit v1.2.3