From a314b3a4549c9655a7f6880edfb38d3f5ef7f676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Tue, 25 Oct 2022 21:58:07 +0200 Subject: [PATCH] fixes some record types and type visibility adds project for autofac setup --- .../ContainerBuilderExtensions.cs | 26 +++++++++++++++++++ .../Piwigo.Client.Autofac.csproj | 17 ++++++++++++ .../Piwigo.Client.Autofac/PiwigoModule.cs | 26 +++++++++++++++++++ .../Piwigo.Client/Contract/AlbumList.cs | 2 +- .../Piwigo.Client/Contract/CheckUpload.cs | 2 +- .../Piwigo.Client/Contract/CommentAdded.cs | 2 +- .../Piwigo.Client/Contract/PagedImages.cs | 12 +-------- .../Piwigo.Client/Contract/PiwigoResponse.cs | 4 +-- .../{ => Contract}/ThumbnailSize.cs | 2 +- PiwigoDotnet/Piwigo.Client/ITagApi.cs | 4 ++- PiwigoDotnet/Piwigo.Client/SessionApi.cs | 2 +- PiwigoDotnet/Piwigo.Client/TagApi.cs | 5 ++++ PiwigoDotnet/PiwigoDotnet.sln | 6 +++++ 13 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 PiwigoDotnet/Piwigo.Client.Autofac/ContainerBuilderExtensions.cs create mode 100644 PiwigoDotnet/Piwigo.Client.Autofac/Piwigo.Client.Autofac.csproj create mode 100644 PiwigoDotnet/Piwigo.Client.Autofac/PiwigoModule.cs rename PiwigoDotnet/Piwigo.Client/{ => Contract}/ThumbnailSize.cs (75%) create mode 100644 PiwigoDotnet/Piwigo.Client/TagApi.cs diff --git a/PiwigoDotnet/Piwigo.Client.Autofac/ContainerBuilderExtensions.cs b/PiwigoDotnet/Piwigo.Client.Autofac/ContainerBuilderExtensions.cs new file mode 100644 index 0000000..b52be40 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Autofac/ContainerBuilderExtensions.cs @@ -0,0 +1,26 @@ +using System.Diagnostics.CodeAnalysis; +using Autofac; + +namespace Piwigo.Client.Autofac; + +[SuppressMessage("ReSharper", "UnusedType.Global")] +[SuppressMessage("ReSharper", "UnusedMember.Global")] +public static class ContainerBuilderExtensions +{ + public static ContainerBuilder RegisterPiwigo(this ContainerBuilder builder, IPiwigoConfiguration configuration) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + builder.RegisterModule(new PiwigoModule(configuration)); + + return builder; + } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client.Autofac/Piwigo.Client.Autofac.csproj b/PiwigoDotnet/Piwigo.Client.Autofac/Piwigo.Client.Autofac.csproj new file mode 100644 index 0000000..0e51dc1 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Autofac/Piwigo.Client.Autofac.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/PiwigoDotnet/Piwigo.Client.Autofac/PiwigoModule.cs b/PiwigoDotnet/Piwigo.Client.Autofac/PiwigoModule.cs new file mode 100644 index 0000000..f2ed545 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client.Autofac/PiwigoModule.cs @@ -0,0 +1,26 @@ +using Autofac; + +namespace Piwigo.Client.Autofac; + +public sealed class PiwigoModule : Module +{ + private readonly IPiwigoConfiguration _configuration; + + public PiwigoModule(IPiwigoConfiguration configuration) + { + _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); + } + + protected override void Load(ContainerBuilder builder) + { + base.Load(builder); + + builder.RegisterInstance(() => _configuration).AsImplementedInterfaces(); + builder.RegisterType().AsImplementedInterfaces().InstancePerLifetimeScope(); + builder.RegisterType().AsImplementedInterfaces(); + builder.RegisterType().AsImplementedInterfaces(); + builder.RegisterType().AsImplementedInterfaces(); + builder.RegisterType().AsImplementedInterfaces(); + builder.RegisterType().AsImplementedInterfaces(); + } +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs b/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs index e79653d..977b824 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/AlbumList.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public record AlbumList +internal record AlbumList { [JsonProperty("Categories")] public IList Albums { get; init; } = null!; diff --git a/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs b/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs index 11f3bcd..fd39462 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/CheckUpload.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public record CheckUpload +internal record CheckUpload { [JsonProperty("message")] public string? Message { get; init; } diff --git a/PiwigoDotnet/Piwigo.Client/Contract/CommentAdded.cs b/PiwigoDotnet/Piwigo.Client/Contract/CommentAdded.cs index 8d7c83d..108bc4f 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/CommentAdded.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/CommentAdded.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public record CommentAdded +internal record CommentAdded { [JsonProperty("comment")] public Comment Comment { get; init; } = null!; diff --git a/PiwigoDotnet/Piwigo.Client/Contract/PagedImages.cs b/PiwigoDotnet/Piwigo.Client/Contract/PagedImages.cs index 683dfa4..7329ea7 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/PagedImages.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/PagedImages.cs @@ -2,18 +2,8 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class PagedImages +public record PagedImages { - protected PagedImages() - { - } - - public PagedImages(ImagePagingInfo paging, IReadOnlyCollection images) - { - Paging = paging ?? throw new ArgumentNullException(nameof(paging)); - Images = images ?? throw new ArgumentNullException(nameof(images)); - } - [JsonProperty("paging")] public ImagePagingInfo Paging { get; init; } = null!; diff --git a/PiwigoDotnet/Piwigo.Client/Contract/PiwigoResponse.cs b/PiwigoDotnet/Piwigo.Client/Contract/PiwigoResponse.cs index e5201b8..7c38b36 100644 --- a/PiwigoDotnet/Piwigo.Client/Contract/PiwigoResponse.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/PiwigoResponse.cs @@ -2,7 +2,7 @@ using Newtonsoft.Json; namespace Piwigo.Client.Contract; -public class PiwigoResponse +public record PiwigoResponse { [JsonIgnore] public bool IsOk => Status is not null && Status.ToLower().Equals("ok"); @@ -17,7 +17,7 @@ public class PiwigoResponse public string? Message { get; init; } } -public class PiwigoResponse : PiwigoResponse +public record PiwigoResponse : PiwigoResponse { [JsonProperty("result")] public T Result { get; init; } = default!; diff --git a/PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs b/PiwigoDotnet/Piwigo.Client/Contract/ThumbnailSize.cs similarity index 75% rename from PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs rename to PiwigoDotnet/Piwigo.Client/Contract/ThumbnailSize.cs index 2ce720b..57ac1ef 100644 --- a/PiwigoDotnet/Piwigo.Client/ThumbnailSize.cs +++ b/PiwigoDotnet/Piwigo.Client/Contract/ThumbnailSize.cs @@ -1,4 +1,4 @@ -namespace Piwigo.Client; +namespace Piwigo.Client.Contract; public enum ThumbnailSize { diff --git a/PiwigoDotnet/Piwigo.Client/ITagApi.cs b/PiwigoDotnet/Piwigo.Client/ITagApi.cs index 373c280..57316cc 100644 --- a/PiwigoDotnet/Piwigo.Client/ITagApi.cs +++ b/PiwigoDotnet/Piwigo.Client/ITagApi.cs @@ -1,3 +1,5 @@ namespace Piwigo.Client; -public interface ITagApi {} \ No newline at end of file +public interface ITagApi +{ +} \ No newline at end of file diff --git a/PiwigoDotnet/Piwigo.Client/SessionApi.cs b/PiwigoDotnet/Piwigo.Client/SessionApi.cs index b996886..4f2523f 100644 --- a/PiwigoDotnet/Piwigo.Client/SessionApi.cs +++ b/PiwigoDotnet/Piwigo.Client/SessionApi.cs @@ -3,7 +3,7 @@ using Piwigo.Client.Contract; namespace Piwigo.Client; -internal class SessionApi : ISessionApi +public class SessionApi : ISessionApi { private readonly IPiwigoContext _context; private readonly ILogger _logger; diff --git a/PiwigoDotnet/Piwigo.Client/TagApi.cs b/PiwigoDotnet/Piwigo.Client/TagApi.cs new file mode 100644 index 0000000..ff0ebb0 --- /dev/null +++ b/PiwigoDotnet/Piwigo.Client/TagApi.cs @@ -0,0 +1,5 @@ +namespace Piwigo.Client; + +public class TagApi : ITagApi +{ +} \ No newline at end of file diff --git a/PiwigoDotnet/PiwigoDotnet.sln b/PiwigoDotnet/PiwigoDotnet.sln index 3c24f79..ad41f94 100644 --- a/PiwigoDotnet/PiwigoDotnet.sln +++ b/PiwigoDotnet/PiwigoDotnet.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piwigo.Client.Tests", "Piwi EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piwigo.Client.Cli", "Piwigo.Client.Cli\Piwigo.Client.Cli.csproj", "{829494FB-DE53-4C65-958D-37036CAB86BD}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Piwigo.Client.Autofac", "Piwigo.Client.Autofac\Piwigo.Client.Autofac.csproj", "{C8247110-D9BB-4658-B36B-7AEB7A42C8EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +26,9 @@ Global {829494FB-DE53-4C65-958D-37036CAB86BD}.Debug|Any CPU.Build.0 = Debug|Any CPU {829494FB-DE53-4C65-958D-37036CAB86BD}.Release|Any CPU.ActiveCfg = Release|Any CPU {829494FB-DE53-4C65-958D-37036CAB86BD}.Release|Any CPU.Build.0 = Release|Any CPU + {C8247110-D9BB-4658-B36B-7AEB7A42C8EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C8247110-D9BB-4658-B36B-7AEB7A42C8EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C8247110-D9BB-4658-B36B-7AEB7A42C8EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C8247110-D9BB-4658-B36B-7AEB7A42C8EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal