adds static CreateClient to make usages without DI container easier

This commit is contained in:
Philipp Häfelfinger 2022-11-17 23:12:39 +01:00
parent b23ef3eebb
commit 34807e6572

View File

@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using Piwigo.Client.Albums; using Piwigo.Client.Albums;
using Piwigo.Client.Images; using Piwigo.Client.Images;
using Piwigo.Client.Session; using Piwigo.Client.Session;
@ -19,4 +20,17 @@ public class PiwigoClient : IPiwigoClient
public ITagApi Tag { get; } public ITagApi Tag { get; }
public ISessionApi Session { get; } public ISessionApi Session { get; }
public IAlbumApi Album { get; } public IAlbumApi Album { get; }
public static IPiwigoClient CreateClient(string baseUri, string userName, string password, ILoggerFactory loggerFactory)
{
var configuration = new PiwigoConfiguration(baseUri, userName, password);
var context = new PiwigoContext(configuration, loggerFactory.CreateLogger<PiwigoContext>());
IImageApi imageApi = new ImageApi(context, loggerFactory.CreateLogger<ImageApi>());
var tagApi = new TagApi(context, loggerFactory.CreateLogger<TagApi>());
var sessionApi = new SessionApi(context, loggerFactory.CreateLogger<SessionApi>());
var albumApi = new AlbumApi(context, loggerFactory.CreateLogger<AlbumApi>());
var piwigoClient = new PiwigoClient(imageApi, tagApi, sessionApi, albumApi);
return piwigoClient;
}
} }