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.
25 using OpenTween.Models;
26 using OpenTween.Setting;
27 using OpenTween.SocialProtocol;
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 AccountCollection AccountCollection
45 => this.accountCollectionLazy.Value;
47 public ImageCache ImageCache
48 => this.imageCacheLazy.Value;
50 public IconAssetsManager IconAssetsManager
51 => this.iconAssetsManagerLazy.Value;
53 public ImgAzyobuziNet ImgAzyobuziNet
54 => this.imgAzyobuziNetLazy.Value;
56 public ThumbnailGenerator ThumbnailGenerator
57 => this.thumbnailGeneratorLazy.Value;
59 public TweenMain MainForm
60 => this.mainFormLazy.Value;
62 private readonly Lazy<CultureService> cultureServiceLazy;
63 private readonly DisposableLazy<AccountCollection> accountCollectionLazy;
64 private readonly DisposableLazy<ImageCache> imageCacheLazy;
65 private readonly DisposableLazy<IconAssetsManager> iconAssetsManagerLazy;
66 private readonly DisposableLazy<ImgAzyobuziNet> imgAzyobuziNetLazy;
67 private readonly Lazy<ThumbnailGenerator> thumbnailGeneratorLazy;
68 private readonly DisposableLazy<TweenMain> mainFormLazy;
70 public ApplicationContainer(SettingManager settings)
72 this.Settings = settings;
73 SettingManager.Instance = settings;
75 this.cultureServiceLazy = new(this.CreateCultureService);
76 this.accountCollectionLazy = new(this.CreateAccountCollection);
77 this.imageCacheLazy = new(this.CreateImageCache);
78 this.iconAssetsManagerLazy = new(this.CreateIconAssetsManager);
79 this.imgAzyobuziNetLazy = new(this.CreateImgAzyobuziNet);
80 this.thumbnailGeneratorLazy = new(this.CreateThumbnailGenerator);
81 this.mainFormLazy = new(this.CreateTweenMain);
84 private CultureService CreateCultureService()
85 => new(this.Settings.Common);
87 private AccountCollection CreateAccountCollection()
90 private ImageCache CreateImageCache()
93 private IconAssetsManager CreateIconAssetsManager()
96 private ImgAzyobuziNet CreateImgAzyobuziNet()
97 => new(autoupdate: false);
99 private ThumbnailGenerator CreateThumbnailGenerator()
100 => new(this.ImgAzyobuziNet);
102 private TweenMain CreateTweenMain()
103 => new(this.Settings, this.TabInfo, this.AccountCollection, this.ImageCache, this.IconAssetsManager, this.ThumbnailGenerator);
105 public void Dispose()
110 this.IsDisposed = true;
111 this.mainFormLazy.Dispose();
112 this.imgAzyobuziNetLazy.Dispose();
113 this.accountCollectionLazy.Dispose();
114 this.iconAssetsManagerLazy.Dispose();
115 this.imageCacheLazy.Dispose();