1 // OpenTween - Client of Twitter
2 // Copyright (c) 2022 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
5 // This file is part of OpenTween.
7 // This program is free software; you can redistribute it and/or modify it
8 // under the terms of the GNU General public License as published by the Free
9 // Software Foundation; either version 3 of the License, or (at your option)
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General public License
17 // You should have received a copy of the GNU General public License along
18 // with this program. If not, see <http://www.gnu.org/licenses/>, or write to
19 // the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 // Boston, MA 02110-1301, USA.
26 using OpenTween.Models;
27 using OpenTween.Setting;
28 using OpenTween.Thumbnail;
29 using OpenTween.Thumbnail.Services;
33 public sealed class ApplicationContainer : IDisposable
35 public bool IsDisposed { get; private set; } = false;
37 public SettingManager Settings { get; }
39 public TabInformations TabInfo { get; } = TabInformations.GetInstance();
41 public CultureService CultureService
42 => this.cultureServiceLazy.Value;
44 public TwitterApi TwitterApi
45 => this.twitterApiLazy.Value;
47 public Twitter Twitter
48 => this.twitterLazy.Value;
50 public ImageCache ImageCache
51 => this.imageCacheLazy.Value;
53 public IconAssetsManager IconAssetsManager
54 => this.iconAssetsManagerLazy.Value;
56 public ImgAzyobuziNet ImgAzyobuziNet
57 => this.imgAzyobuziNetLazy.Value;
59 public ThumbnailGenerator ThumbnailGenerator
60 => this.thumbnailGeneratorLazy.Value;
62 public TweenMain MainForm
63 => this.mainFormLazy.Value;
65 private readonly Lazy<CultureService> cultureServiceLazy;
66 private readonly DisposableLazy<TwitterApi> twitterApiLazy;
67 private readonly DisposableLazy<Twitter> twitterLazy;
68 private readonly DisposableLazy<ImageCache> imageCacheLazy;
69 private readonly DisposableLazy<IconAssetsManager> iconAssetsManagerLazy;
70 private readonly DisposableLazy<ImgAzyobuziNet> imgAzyobuziNetLazy;
71 private readonly Lazy<ThumbnailGenerator> thumbnailGeneratorLazy;
72 private readonly DisposableLazy<TweenMain> mainFormLazy;
74 public ApplicationContainer(SettingManager settings)
76 this.Settings = settings;
77 SettingManager.Instance = settings;
79 this.cultureServiceLazy = new(this.CreateCultureService);
80 this.twitterApiLazy = new(this.CreateTwitterApi);
81 this.twitterLazy = new(this.CreateTwitter);
82 this.imageCacheLazy = new(this.CreateImageCache);
83 this.iconAssetsManagerLazy = new(this.CreateIconAssetsManager);
84 this.imgAzyobuziNetLazy = new(this.CreateImgAzyobuziNet);
85 this.thumbnailGeneratorLazy = new(this.CreateThumbnailGenerator);
86 this.mainFormLazy = new(this.CreateTweenMain);
89 private CultureService CreateCultureService()
90 => new(this.Settings.Common);
92 private TwitterApi CreateTwitterApi()
95 private Twitter CreateTwitter()
96 => new(this.TwitterApi);
98 private ImageCache CreateImageCache()
101 private IconAssetsManager CreateIconAssetsManager()
104 private ImgAzyobuziNet CreateImgAzyobuziNet()
105 => new(autoupdate: false);
107 private ThumbnailGenerator CreateThumbnailGenerator()
108 => new(this.ImgAzyobuziNet);
110 private TweenMain CreateTweenMain()
111 => new(this.Settings, this.TabInfo, this.Twitter, this.ImageCache, this.IconAssetsManager, this.ThumbnailGenerator);
113 public void Dispose()
118 this.IsDisposed = true;
119 this.mainFormLazy.Dispose();
120 this.imgAzyobuziNetLazy.Dispose();
121 this.twitterLazy.Dispose();
122 this.twitterApiLazy.Dispose();
123 this.iconAssetsManagerLazy.Dispose();
124 this.imageCacheLazy.Dispose();