From 6c9778b55dd8367d38280c66e0f308c5332029ed Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Apr 2021 18:38:26 +0800 Subject: refactor: Refactor is still on... --- BackEnd/Timeline/Services/Data/DataManager.cs | 6 +++--- BackEnd/Timeline/Services/Data/DataManagerExtensions.cs | 5 +++-- .../Data/DataServicesServiceCollectionExtensions.cs | 15 +++++++++++++++ BackEnd/Timeline/Services/Data/IDataManager.cs | 6 +++--- 4 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs (limited to 'BackEnd/Timeline/Services/Data') diff --git a/BackEnd/Timeline/Services/Data/DataManager.cs b/BackEnd/Timeline/Services/Data/DataManager.cs index 9de17da3..6cf3225f 100644 --- a/BackEnd/Timeline/Services/Data/DataManager.cs +++ b/BackEnd/Timeline/Services/Data/DataManager.cs @@ -21,7 +21,7 @@ namespace Timeline.Services.Data _eTagGenerator = eTagGenerator; } - public async Task RetainEntry(byte[] data, CancellationToken cancellationToken = default) + public async Task RetainEntryAsync(byte[] data, CancellationToken cancellationToken = default) { if (data == null) throw new ArgumentNullException(nameof(data)); @@ -56,7 +56,7 @@ namespace Timeline.Services.Data return tag; } - public async Task FreeEntry(string tag, CancellationToken cancellationToken = default) + public async Task FreeEntryAsync(string tag, CancellationToken cancellationToken = default) { if (tag == null) throw new ArgumentNullException(nameof(tag)); @@ -87,7 +87,7 @@ namespace Timeline.Services.Data } } - public async Task GetEntry(string tag, CancellationToken cancellationToken = default) + public async Task GetEntryAsync(string tag, CancellationToken cancellationToken = default) { if (tag == null) throw new ArgumentNullException(nameof(tag)); diff --git a/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs b/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs index 64d35b9b..d149f3fa 100644 --- a/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs +++ b/BackEnd/Timeline/Services/Data/DataManagerExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; namespace Timeline.Services.Data @@ -8,7 +9,7 @@ namespace Timeline.Services.Data /// /// Try to get an entry and throw if not exist. /// - public static async Task GetEntryAndCheck(this IDataManager dataManager, string tag, string notExistMessage) + public static async Task GetEntryAndCheck(this IDataManager dataManager, string tag, string notExistMessage, CancellationToken cancellationToken = default) { if (dataManager is null) throw new ArgumentNullException(nameof(dataManager)); @@ -17,7 +18,7 @@ namespace Timeline.Services.Data if (notExistMessage is null) throw new ArgumentNullException(nameof(notExistMessage)); - var data = await dataManager.GetEntry(tag); + var data = await dataManager.GetEntryAsync(tag, cancellationToken); if (data is null) throw new DatabaseCorruptedException(string.Format(Resource.GetEntryAndCheckNotExist, tag, notExistMessage)); return data; diff --git a/BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs b/BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs new file mode 100644 index 00000000..2717e63c --- /dev/null +++ b/BackEnd/Timeline/Services/Data/DataServicesServiceCollectionExtensions.cs @@ -0,0 +1,15 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace Timeline.Services.Data +{ + public static class DataServicesServiceCollectionExtensions + { + public static IServiceCollection AddDataServices(this IServiceCollection services) + { + services.TryAddScoped(); + services.TryAddScoped(); + return services; + } + } +} diff --git a/BackEnd/Timeline/Services/Data/IDataManager.cs b/BackEnd/Timeline/Services/Data/IDataManager.cs index 6a87c1b2..4191367e 100644 --- a/BackEnd/Timeline/Services/Data/IDataManager.cs +++ b/BackEnd/Timeline/Services/Data/IDataManager.cs @@ -23,7 +23,7 @@ namespace Timeline.Services.Data /// Cancellation token. /// The tag of the created entry. /// Thrown when is null. - public Task RetainEntry(byte[] data, CancellationToken cancellationToken = default); + public Task RetainEntryAsync(byte[] data, CancellationToken cancellationToken = default); /// /// Decrease the the ref count of the entry. @@ -35,7 +35,7 @@ namespace Timeline.Services.Data /// /// It's no-op if entry with tag does not exist. /// - public Task FreeEntry(string tag, CancellationToken cancellationToken = default); + public Task FreeEntryAsync(string tag, CancellationToken cancellationToken = default); /// /// Retrieve the entry with given tag. If not exist, returns null. @@ -44,6 +44,6 @@ namespace Timeline.Services.Data /// Cancellation token. /// The data of the entry. If not exist, returns null. /// Thrown when is null. - public Task GetEntry(string tag, CancellationToken cancellationToken = default); + public Task GetEntryAsync(string tag, CancellationToken cancellationToken = default); } } -- cgit v1.2.3