// OpenTween - Client of Twitter // Copyright (c) 2022 kim_upsilon (@kim_upsilon) // All rights reserved. // // This file is part of OpenTween. // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU 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 General public License // for more details. // // You should have received a copy of the GNU General public License along // with this program. If not, see , or write to // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, // Boston, MA 02110-1301, USA. #nullable enable using System; using OpenTween.Models; using OpenTween.Setting; using OpenTween.SocialProtocol; using OpenTween.Thumbnail; using OpenTween.Thumbnail.Services; namespace OpenTween { public sealed class ApplicationContainer : IDisposable { public bool IsDisposed { get; private set; } = false; public SettingManager Settings { get; } public TabInformations TabInfo { get; } = TabInformations.GetInstance(); public CultureService CultureService => this.cultureServiceLazy.Value; public AccountCollection AccountCollection => this.accountCollectionLazy.Value; public ImageCache ImageCache => this.imageCacheLazy.Value; public IconAssetsManager IconAssetsManager => this.iconAssetsManagerLazy.Value; public ImgAzyobuziNet ImgAzyobuziNet => this.imgAzyobuziNetLazy.Value; public ThumbnailGenerator ThumbnailGenerator => this.thumbnailGeneratorLazy.Value; public TweenMain MainForm => this.mainFormLazy.Value; private readonly Lazy cultureServiceLazy; private readonly DisposableLazy accountCollectionLazy; private readonly DisposableLazy imageCacheLazy; private readonly DisposableLazy iconAssetsManagerLazy; private readonly DisposableLazy imgAzyobuziNetLazy; private readonly Lazy thumbnailGeneratorLazy; private readonly DisposableLazy mainFormLazy; public ApplicationContainer(SettingManager settings) { this.Settings = settings; SettingManager.Instance = settings; this.cultureServiceLazy = new(this.CreateCultureService); this.accountCollectionLazy = new(this.CreateAccountCollection); this.imageCacheLazy = new(this.CreateImageCache); this.iconAssetsManagerLazy = new(this.CreateIconAssetsManager); this.imgAzyobuziNetLazy = new(this.CreateImgAzyobuziNet); this.thumbnailGeneratorLazy = new(this.CreateThumbnailGenerator); this.mainFormLazy = new(this.CreateTweenMain); } private CultureService CreateCultureService() => new(this.Settings.Common); private AccountCollection CreateAccountCollection() => new(); private ImageCache CreateImageCache() => new(); private IconAssetsManager CreateIconAssetsManager() => new(); private ImgAzyobuziNet CreateImgAzyobuziNet() => new(autoupdate: false); private ThumbnailGenerator CreateThumbnailGenerator() => new(this.ImgAzyobuziNet); private TweenMain CreateTweenMain() => new(this.Settings, this.TabInfo, this.AccountCollection, this.ImageCache, this.IconAssetsManager, this.ThumbnailGenerator); public void Dispose() { if (this.IsDisposed) return; this.IsDisposed = true; this.mainFormLazy.Dispose(); this.imgAzyobuziNetLazy.Dispose(); this.accountCollectionLazy.Dispose(); this.iconAssetsManagerLazy.Dispose(); this.imageCacheLazy.Dispose(); } } }