OSDN Git Service

PostMultipartRequestクラスを追加
[opentween/open-tween.git] / OpenTween / ApplicationContainer.cs
1 // OpenTween - Client of Twitter
2 // Copyright (c) 2022 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
3 // All rights reserved.
4 //
5 // This file is part of OpenTween.
6 //
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)
10 // any later version.
11 //
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
15 // for more details.
16 //
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.
21
22 #nullable enable
23
24 using System;
25 using OpenTween.Api;
26 using OpenTween.Models;
27 using OpenTween.Setting;
28 using OpenTween.Thumbnail;
29 using OpenTween.Thumbnail.Services;
30
31 namespace OpenTween
32 {
33     public sealed class ApplicationContainer : IDisposable
34     {
35         public bool IsDisposed { get; private set; } = false;
36
37         public SettingManager Settings { get; }
38
39         public TabInformations TabInfo { get; } = TabInformations.GetInstance();
40
41         public CultureService CultureService
42             => this.cultureServiceLazy.Value;
43
44         public TwitterApi TwitterApi
45             => this.twitterApiLazy.Value;
46
47         public Twitter Twitter
48             => this.twitterLazy.Value;
49
50         public ImageCache ImageCache
51             => this.imageCacheLazy.Value;
52
53         public IconAssetsManager IconAssetsManager
54             => this.iconAssetsManagerLazy.Value;
55
56         public ImgAzyobuziNet ImgAzyobuziNet
57             => this.imgAzyobuziNetLazy.Value;
58
59         public ThumbnailGenerator ThumbnailGenerator
60             => this.thumbnailGeneratorLazy.Value;
61
62         public TweenMain MainForm
63             => this.mainFormLazy.Value;
64
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;
73
74         public ApplicationContainer(SettingManager settings)
75         {
76             this.Settings = settings;
77             SettingManager.Instance = settings;
78
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);
87         }
88
89         private CultureService CreateCultureService()
90             => new(this.Settings.Common);
91
92         private TwitterApi CreateTwitterApi()
93             => new();
94
95         private Twitter CreateTwitter()
96             => new(this.TwitterApi);
97
98         private ImageCache CreateImageCache()
99             => new();
100
101         private IconAssetsManager CreateIconAssetsManager()
102             => new();
103
104         private ImgAzyobuziNet CreateImgAzyobuziNet()
105             => new(autoupdate: false);
106
107         private ThumbnailGenerator CreateThumbnailGenerator()
108             => new(this.ImgAzyobuziNet);
109
110         private TweenMain CreateTweenMain()
111             => new(this.Settings, this.TabInfo, this.Twitter, this.ImageCache, this.IconAssetsManager, this.ThumbnailGenerator);
112
113         public void Dispose()
114         {
115             if (this.IsDisposed)
116                 return;
117
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();
125         }
126     }
127 }