aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-04-27 19:37:11 +0800
committercrupest <crupest@outlook.com>2021-04-27 19:37:11 +0800
commitac309245d21f16c06abe2d1d9bb260e094d0805e (patch)
tree2ed691e4853aae0a527d4c9b7c0d00a4cf07a3af
parenta6150c487e7a0eb3fb1d9874d2fa7de61cdbfd30 (diff)
downloadtimeline-ac309245d21f16c06abe2d1d9bb260e094d0805e.tar.gz
timeline-ac309245d21f16c06abe2d1d9bb260e094d0805e.tar.bz2
timeline-ac309245d21f16c06abe2d1d9bb260e094d0805e.zip
refactor: ...
-rw-r--r--BackEnd/Timeline/Resources/Services/UserAvatarService.Designer.cs108
-rw-r--r--BackEnd/Timeline/Resources/Services/UserAvatarService.resx135
-rw-r--r--BackEnd/Timeline/Services/User/Avatar/DefaultUserAvatarProvider.cs51
-rw-r--r--BackEnd/Timeline/Services/User/Avatar/IDefaultUserAvatarProvider.cs27
-rw-r--r--BackEnd/Timeline/Services/User/Avatar/IUserAvatarService.cs45
-rw-r--r--BackEnd/Timeline/Services/User/Avatar/UserAvatarService.cs (renamed from BackEnd/Timeline/Services/User/UserAvatarService.cs)124
-rw-r--r--BackEnd/Timeline/Services/User/Avatar/UserAvatarServicesServiceCollectionExtensions.cs14
-rw-r--r--BackEnd/Timeline/Services/User/UserServicesServiceCollectionExtensions.cs26
-rw-r--r--BackEnd/Timeline/Startup.cs17
-rw-r--r--BackEnd/Timeline/Timeline.csproj9
10 files changed, 174 insertions, 382 deletions
diff --git a/BackEnd/Timeline/Resources/Services/UserAvatarService.Designer.cs b/BackEnd/Timeline/Resources/Services/UserAvatarService.Designer.cs
deleted file mode 100644
index c72d4215..00000000
--- a/BackEnd/Timeline/Resources/Services/UserAvatarService.Designer.cs
+++ /dev/null
@@ -1,108 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-// This code was generated by a tool.
-// Runtime Version:4.0.30319.42000
-//
-// Changes to this file may cause incorrect behavior and will be lost if
-// the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-namespace Timeline.Resources.Services {
- using System;
-
-
- /// <summary>
- /// A strongly-typed resource class, for looking up localized strings, etc.
- /// </summary>
- // This class was auto-generated by the StronglyTypedResourceBuilder
- // class via a tool like ResGen or Visual Studio.
- // To add or remove a member, edit your .ResX file then rerun ResGen
- // with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
- [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
- [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- internal class UserAvatarService {
-
- private static global::System.Resources.ResourceManager resourceMan;
-
- private static global::System.Globalization.CultureInfo resourceCulture;
-
- [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
- internal UserAvatarService() {
- }
-
- /// <summary>
- /// Returns the cached ResourceManager instance used by this class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Resources.ResourceManager ResourceManager {
- get {
- if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Timeline.Resources.Services.UserAvatarService", typeof(UserAvatarService).Assembly);
- resourceMan = temp;
- }
- return resourceMan;
- }
- }
-
- /// <summary>
- /// Overrides the current thread's CurrentUICulture property for all
- /// resource lookups using this strongly typed resource class.
- /// </summary>
- [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
- internal static global::System.Globalization.CultureInfo Culture {
- get {
- return resourceCulture;
- }
- set {
- resourceCulture = value;
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Data of avatar is null..
- /// </summary>
- internal static string ExceptionAvatarDataNull {
- get {
- return ResourceManager.GetString("ExceptionAvatarDataNull", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Type of avatar is null or empty..
- /// </summary>
- internal static string ExceptionAvatarTypeNullOrEmpty {
- get {
- return ResourceManager.GetString("ExceptionAvatarTypeNullOrEmpty", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Database corupted! One of type and data of a avatar is null but the other is not..
- /// </summary>
- internal static string ExceptionDatabaseCorruptedDataAndTypeNotSame {
- get {
- return ResourceManager.GetString("ExceptionDatabaseCorruptedDataAndTypeNotSame", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Created an entry in user_avatars..
- /// </summary>
- internal static string LogCreateEntity {
- get {
- return ResourceManager.GetString("LogCreateEntity", resourceCulture);
- }
- }
-
- /// <summary>
- /// Looks up a localized string similar to Updated an entry in user_avatars..
- /// </summary>
- internal static string LogUpdateEntity {
- get {
- return ResourceManager.GetString("LogUpdateEntity", resourceCulture);
- }
- }
- }
-}
diff --git a/BackEnd/Timeline/Resources/Services/UserAvatarService.resx b/BackEnd/Timeline/Resources/Services/UserAvatarService.resx
deleted file mode 100644
index da9d7203..00000000
--- a/BackEnd/Timeline/Resources/Services/UserAvatarService.resx
+++ /dev/null
@@ -1,135 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<root>
- <!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name="resmimetype">text/microsoft-resx</resheader>
- <resheader name="version">2.0</resheader>
- <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
- <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of "resheader" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
- <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
- <xsd:element name="root" msdata:IsDataSet="true">
- <xsd:complexType>
- <xsd:choice maxOccurs="unbounded">
- <xsd:element name="metadata">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" />
- </xsd:sequence>
- <xsd:attribute name="name" use="required" type="xsd:string" />
- <xsd:attribute name="type" type="xsd:string" />
- <xsd:attribute name="mimetype" type="xsd:string" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="assembly">
- <xsd:complexType>
- <xsd:attribute name="alias" type="xsd:string" />
- <xsd:attribute name="name" type="xsd:string" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="data">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
- <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
- <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="resheader">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <resheader name="resmimetype">
- <value>text/microsoft-resx</value>
- </resheader>
- <resheader name="version">
- <value>2.0</value>
- </resheader>
- <resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <data name="ExceptionAvatarDataNull" xml:space="preserve">
- <value>Data of avatar is null.</value>
- </data>
- <data name="ExceptionAvatarTypeNullOrEmpty" xml:space="preserve">
- <value>Type of avatar is null or empty.</value>
- </data>
- <data name="ExceptionDatabaseCorruptedDataAndTypeNotSame" xml:space="preserve">
- <value>Database corupted! One of type and data of a avatar is null but the other is not.</value>
- </data>
- <data name="LogCreateEntity" xml:space="preserve">
- <value>Created an entry in user_avatars.</value>
- </data>
- <data name="LogUpdateEntity" xml:space="preserve">
- <value>Updated an entry in user_avatars.</value>
- </data>
-</root> \ No newline at end of file
diff --git a/BackEnd/Timeline/Services/User/Avatar/DefaultUserAvatarProvider.cs b/BackEnd/Timeline/Services/User/Avatar/DefaultUserAvatarProvider.cs
new file mode 100644
index 00000000..9f8f1c62
--- /dev/null
+++ b/BackEnd/Timeline/Services/User/Avatar/DefaultUserAvatarProvider.cs
@@ -0,0 +1,51 @@
+using Microsoft.AspNetCore.Hosting;
+using SixLabors.ImageSharp;
+using System.IO;
+using System.Threading.Tasks;
+using Timeline.Helpers.Cache;
+using Timeline.Models;
+using Timeline.Services.Data;
+
+namespace Timeline.Services.User.Avatar
+{
+ // TODO! : Make this configurable.
+ public class DefaultUserAvatarProvider : IDefaultUserAvatarProvider
+ {
+ private readonly IETagGenerator _eTagGenerator;
+
+ private readonly string _avatarPath;
+
+ private CacheableDataDigest? _cacheDigest;
+ private ByteData? _cacheData;
+
+ public DefaultUserAvatarProvider(IWebHostEnvironment environment, IETagGenerator eTagGenerator)
+ {
+ _avatarPath = Path.Combine(environment.ContentRootPath, "default-avatar.png");
+ _eTagGenerator = eTagGenerator;
+ }
+
+ private async Task CheckAndInit()
+ {
+ var path = _avatarPath;
+ if (_cacheData == null || File.GetLastWriteTime(path) > _cacheDigest!.LastModified)
+ {
+ var data = await File.ReadAllBytesAsync(path);
+ _cacheDigest = new CacheableDataDigest(await _eTagGenerator.GenerateETagAsync(data), File.GetLastWriteTime(path));
+ Image.Identify(data, out var format);
+ _cacheData = new ByteData(data, format.DefaultMimeType);
+ }
+ }
+
+ public async Task<ICacheableDataDigest> GetDefaultAvatarDigest()
+ {
+ await CheckAndInit();
+ return _cacheDigest!;
+ }
+
+ public async Task<ByteData> GetDefaultAvatar()
+ {
+ await CheckAndInit();
+ return _cacheData!;
+ }
+ }
+}
diff --git a/BackEnd/Timeline/Services/User/Avatar/IDefaultUserAvatarProvider.cs b/BackEnd/Timeline/Services/User/Avatar/IDefaultUserAvatarProvider.cs
new file mode 100644
index 00000000..50c9ac91
--- /dev/null
+++ b/BackEnd/Timeline/Services/User/Avatar/IDefaultUserAvatarProvider.cs
@@ -0,0 +1,27 @@
+using System.Threading.Tasks;
+using Timeline.Helpers.Cache;
+using Timeline.Models;
+
+namespace Timeline.Services.User.Avatar
+{
+ /// <summary>
+ /// Provider for default user avatar.
+ /// </summary>
+ /// <remarks>
+ /// Mainly for unit tests.
+ /// </remarks>
+ public interface IDefaultUserAvatarProvider
+ {
+ /// <summary>
+ /// Get the digest of default avatar.
+ /// </summary>
+ /// <returns>The digest.</returns>
+ Task<ICacheableDataDigest> GetDefaultAvatarDigest();
+
+ /// <summary>
+ /// Get the default avatar.
+ /// </summary>
+ /// <returns>The avatar.</returns>
+ Task<ByteData> GetDefaultAvatar();
+ }
+}
diff --git a/BackEnd/Timeline/Services/User/Avatar/IUserAvatarService.cs b/BackEnd/Timeline/Services/User/Avatar/IUserAvatarService.cs
new file mode 100644
index 00000000..fda35aac
--- /dev/null
+++ b/BackEnd/Timeline/Services/User/Avatar/IUserAvatarService.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Threading.Tasks;
+using Timeline.Helpers.Cache;
+using Timeline.Models;
+using Timeline.Services.Imaging;
+
+namespace Timeline.Services.User.Avatar
+{
+ public interface IUserAvatarService
+ {
+ /// <summary>
+ /// Get avatar digest of a user.
+ /// </summary>
+ /// <param name="userId">User id.</param>
+ /// <returns>The avatar digest.</returns>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ Task<ICacheableDataDigest> GetAvatarDigest(long userId);
+
+ /// <summary>
+ /// Get avatar of a user. If the user has no avatar set, a default one is returned.
+ /// </summary>
+ /// <param name="userId">User id.</param>
+ /// <returns>The avatar.</returns>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ Task<ByteData> GetAvatar(long userId);
+
+ /// <summary>
+ /// Set avatar for a user.
+ /// </summary>
+ /// <param name="userId">User id.</param>
+ /// <param name="avatar">The new avatar data.</param>
+ /// <returns>The digest of the avatar.</returns>
+ /// <exception cref="ArgumentNullException">Thrown if <paramref name="avatar"/> is null.</exception>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ /// <exception cref="ImageException">Thrown if avatar is of bad format.</exception>
+ Task<ICacheableDataDigest> SetAvatar(long userId, ByteData avatar);
+
+ /// <summary>
+ /// Remove avatar of a user.
+ /// </summary>
+ /// <param name="userId">User id.</param>
+ /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
+ Task DeleteAvatar(long userId);
+ }
+}
diff --git a/BackEnd/Timeline/Services/User/UserAvatarService.cs b/BackEnd/Timeline/Services/User/Avatar/UserAvatarService.cs
index 9f59624d..4f943e3a 100644
--- a/BackEnd/Timeline/Services/User/UserAvatarService.cs
+++ b/BackEnd/Timeline/Services/User/Avatar/UserAvatarService.cs
@@ -1,10 +1,6 @@
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.EntityFrameworkCore;
-using Microsoft.Extensions.DependencyInjection;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
-using SixLabors.ImageSharp;
using System;
-using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;
@@ -13,114 +9,15 @@ using Timeline.Models;
using Timeline.Services.Data;
using Timeline.Services.Imaging;
-namespace Timeline.Services.User
+namespace Timeline.Services.User.Avatar
{
- /// <summary>
- /// Provider for default user avatar.
- /// </summary>
- /// <remarks>
- /// Mainly for unit tests.
- /// </remarks>
- public interface IDefaultUserAvatarProvider
- {
- /// <summary>
- /// Get the digest of default avatar.
- /// </summary>
- /// <returns>The digest.</returns>
- Task<ICacheableDataDigest> GetDefaultAvatarDigest();
-
- /// <summary>
- /// Get the default avatar.
- /// </summary>
- /// <returns>The avatar.</returns>
- Task<ByteData> GetDefaultAvatar();
- }
-
- public interface IUserAvatarService
- {
- /// <summary>
- /// Get avatar digest of a user.
- /// </summary>
- /// <param name="userId">User id.</param>
- /// <returns>The avatar digest.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- Task<ICacheableDataDigest> GetAvatarDigest(long userId);
-
- /// <summary>
- /// Get avatar of a user. If the user has no avatar set, a default one is returned.
- /// </summary>
- /// <param name="userId">User id.</param>
- /// <returns>The avatar.</returns>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- Task<ByteData> GetAvatar(long userId);
-
- /// <summary>
- /// Set avatar for a user.
- /// </summary>
- /// <param name="userId">User id.</param>
- /// <param name="avatar">The new avatar data.</param>
- /// <returns>The digest of the avatar.</returns>
- /// <exception cref="ArgumentNullException">Thrown if <paramref name="avatar"/> is null.</exception>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- /// <exception cref="ImageException">Thrown if avatar is of bad format.</exception>
- Task<ICacheableDataDigest> SetAvatar(long userId, ByteData avatar);
-
- /// <summary>
- /// Remove avatar of a user.
- /// </summary>
- /// <param name="userId">User id.</param>
- /// <exception cref="UserNotExistException">Thrown when user does not exist.</exception>
- Task DeleteAvatar(long userId);
- }
-
- // TODO! : Make this configurable.
- public class DefaultUserAvatarProvider : IDefaultUserAvatarProvider
- {
- private readonly IETagGenerator _eTagGenerator;
-
- private readonly string _avatarPath;
-
- private CacheableDataDigest? _cacheDigest;
- private ByteData? _cacheData;
-
- public DefaultUserAvatarProvider(IWebHostEnvironment environment, IETagGenerator eTagGenerator)
- {
- _avatarPath = Path.Combine(environment.ContentRootPath, "default-avatar.png");
- _eTagGenerator = eTagGenerator;
- }
-
- private async Task CheckAndInit()
- {
- var path = _avatarPath;
- if (_cacheData == null || File.GetLastWriteTime(path) > _cacheDigest!.LastModified)
- {
- var data = await File.ReadAllBytesAsync(path);
- _cacheDigest = new CacheableDataDigest(await _eTagGenerator.GenerateETagAsync(data), File.GetLastWriteTime(path));
- Image.Identify(data, out var format);
- _cacheData = new ByteData(data, format.DefaultMimeType);
- }
- }
-
- public async Task<ICacheableDataDigest> GetDefaultAvatarDigest()
- {
- await CheckAndInit();
- return _cacheDigest!;
- }
-
- public async Task<ByteData> GetDefaultAvatar()
- {
- await CheckAndInit();
- return _cacheData!;
- }
- }
-
public class UserAvatarService : IUserAvatarService
{
private readonly ILogger<UserAvatarService> _logger;
private readonly DatabaseContext _database;
private readonly IBasicUserService _basicUserService;
private readonly IDefaultUserAvatarProvider _defaultUserAvatarProvider;
- private readonly IImageService _imageValidator;
+ private readonly IImageService _imageService;
private readonly IDataManager _dataManager;
private readonly IClock _clock;
@@ -137,7 +34,7 @@ namespace Timeline.Services.User
_database = database;
_basicUserService = basicUserService;
_defaultUserAvatarProvider = defaultUserAvatarProvider;
- _imageValidator = imageValidator;
+ _imageService = imageValidator;
_dataManager = dataManager;
_clock = clock;
}
@@ -179,7 +76,7 @@ namespace Timeline.Services.User
if (entity.Type is null)
{
- Image.Identify(data, out var format);
+ var format = await _imageService.DetectFormatAsync(data);
entity.Type = format.DefaultMimeType;
await _database.SaveChangesAsync();
}
@@ -192,7 +89,7 @@ namespace Timeline.Services.User
if (avatar is null)
throw new ArgumentNullException(nameof(avatar));
- await _imageValidator.ValidateAsync(avatar.Data, avatar.ContentType, true);
+ await _imageService.ValidateAsync(avatar.Data, avatar.ContentType, true);
await _basicUserService.ThrowIfUserNotExist(userId);
@@ -254,13 +151,4 @@ namespace Timeline.Services.User
await transaction.CommitAsync();
}
}
-
- public static class UserAvatarServiceCollectionExtensions
- {
- public static void AddUserAvatarService(this IServiceCollection services)
- {
- services.AddScoped<IUserAvatarService, UserAvatarService>();
- services.AddScoped<IDefaultUserAvatarProvider, DefaultUserAvatarProvider>();
- }
- }
}
diff --git a/BackEnd/Timeline/Services/User/Avatar/UserAvatarServicesServiceCollectionExtensions.cs b/BackEnd/Timeline/Services/User/Avatar/UserAvatarServicesServiceCollectionExtensions.cs
new file mode 100644
index 00000000..57279855
--- /dev/null
+++ b/BackEnd/Timeline/Services/User/Avatar/UserAvatarServicesServiceCollectionExtensions.cs
@@ -0,0 +1,14 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
+namespace Timeline.Services.User.Avatar
+{
+ public static class UserAvatarServicesServiceCollectionExtensions
+ {
+ public static void AddUserAvatarServices(this IServiceCollection services)
+ {
+ services.TryAddScoped<IUserAvatarService, UserAvatarService>();
+ services.TryAddScoped<IDefaultUserAvatarProvider, DefaultUserAvatarProvider>();
+ }
+ }
+}
diff --git a/BackEnd/Timeline/Services/User/UserServicesServiceCollectionExtensions.cs b/BackEnd/Timeline/Services/User/UserServicesServiceCollectionExtensions.cs
new file mode 100644
index 00000000..6320b608
--- /dev/null
+++ b/BackEnd/Timeline/Services/User/UserServicesServiceCollectionExtensions.cs
@@ -0,0 +1,26 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Timeline.Services.User.Avatar;
+
+namespace Timeline.Services.User
+{
+ public static class UserServicesServiceCollectionExtensions
+ {
+ public static IServiceCollection AddUserServices(this IServiceCollection services)
+ {
+ services.TryAddTransient<IPasswordService, PasswordService>();
+ services.TryAddScoped<IBasicUserService, BasicUserService>();
+ services.TryAddScoped<IUserService, UserService>();
+ services.TryAddScoped<IUserDeleteService, UserDeleteService>();
+ services.TryAddScoped<IUserPermissionService, UserPermissionService>();
+
+ services.AddUserAvatarServices();
+
+ return services;
+ }
+ }
+}
diff --git a/BackEnd/Timeline/Startup.cs b/BackEnd/Timeline/Startup.cs
index c0873113..32208d53 100644
--- a/BackEnd/Timeline/Startup.cs
+++ b/BackEnd/Timeline/Startup.cs
@@ -86,11 +86,6 @@ namespace Timeline
services.AddAuthorization();
services.AddSingleton<IAuthorizationPolicyProvider, PermissionPolicyProvider>();
- services.AddBasicServices();
- services.AddDatabaseManagementService();
- services.AddDataServices();
- services.AddImageServices();
-
services.AddAutoMapper(GetType().Assembly);
services.AddMappers();
@@ -100,13 +95,11 @@ namespace Timeline
options.UseSqlite($"Data Source={pathProvider.GetDatabaseFilePath()}");
});
- services.AddTransient<IPasswordService, PasswordService>();
- services.AddScoped<IBasicUserService, BasicUserService>();
- services.AddScoped<IUserService, UserService>();
- services.AddScoped<IUserDeleteService, UserDeleteService>();
- services.AddScoped<IUserPermissionService, UserPermissionService>();
- services.AddUserAvatarService();
-
+ services.AddBasicServices();
+ services.AddDatabaseManagementService();
+ services.AddDataServices();
+ services.AddImageServices();
+ services.AddUserServices();
services.AddTokenService(Configuration);
services.AddScoped<IBasicTimelineService, BasicTimelineService>();
diff --git a/BackEnd/Timeline/Timeline.csproj b/BackEnd/Timeline/Timeline.csproj
index dc41a7f8..4c40f209 100644
--- a/BackEnd/Timeline/Timeline.csproj
+++ b/BackEnd/Timeline/Timeline.csproj
@@ -128,11 +128,6 @@
<AutoGen>True</AutoGen>
<DependentUpon>TimelineService.resx</DependentUpon>
</Compile>
- <Compile Update="Resources\Services\UserAvatarService.Designer.cs">
- <DesignTime>True</DesignTime>
- <AutoGen>True</AutoGen>
- <DependentUpon>UserAvatarService.resx</DependentUpon>
- </Compile>
<Compile Update="Resources\Services\UserTokenService.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@@ -241,10 +236,6 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>TimelineService.Designer.cs</LastGenOutput>
</EmbeddedResource>
- <EmbeddedResource Update="Resources\Services\UserAvatarService.resx">
- <Generator>ResXFileCodeGenerator</Generator>
- <LastGenOutput>UserAvatarService.Designer.cs</LastGenOutput>
- </EmbeddedResource>
<EmbeddedResource Update="Resources\Services\UserTokenService.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>UserTokenService.Designer.cs</LastGenOutput>