Skip to main content
カプセル化や関心ごとの分離による継続的インテグレーション例と
グローバリゼーションへの応用
ASP.NET Core のグローバリゼーションおよびローカリゼー
https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/localization?view=aspnetcore-6.0
Profile
•ブログ : http://blog.processtune.com
•プロフィール : Facebook, Twitter or Microsoft MVP Website
•コミュニティ : .NETラボの運営スタッフ
•Microsoft MVP : July 2010 ~ Jun 2022
•Current expertise : MVP for Developer Technologies
Solutions Architect
システム構築のプロセス評価、改善、策定、開発フ
レームワークの設計、実装管理、プリセールスやプロ
ジェクトの立ち上げなど
オプションズ・パターンによるカプセル化
オプションズ・パターンによる関心ごとの分
オプションズ・パターンによるグローバリゼ
PoCと継続的インテグレーション
Agenda
xxController.cs
コンストラクタ
(サービス取
得)
(クラス・ス
コープの変数に
格納)
xxController.cs
各メソッド
(変数を利用)
ASP.NET Core Options Patternの仕組み
JSONファイル
Project.cs
サービス登録
xxController.cs
コンストラクタ
(サービス取
得)
(クラス・ス
コープの変数に
格納)
xxController.cs
各メソッド
(変数を利用)
ASP.NET Core Options Patternの仕組み
JSONファイル
Project.cs
サービス登録
xxController.cs
コンストラクタ
(サービス取
得)
(クラス・ス
コープの変数に
格納)
xxController.cs
各メソッド
(変数を利用)
ASP.NET Core Options Patternの仕組み
JSONファイル
Project.cs
サービス登録
フィールド以外で構成されたインスタンスを生成
resxファイルでのオブジェクト定義
WTI Converter
https://converter.webtranslateit.com/
Android .xml (xml)
Comma Separated Value (CSV) (csv)
Java .xml (xml)
jQuery-glob (as a hash) (js)
jQuery-glob (as a list) (js)
JSON (json, js, resjson)
MicroDVD .sub (sub)
Windows Installer .nsh (nsh)
PHP Array (php, inc)
PHP ArrayList (php, inc)
PHP Define (php, inc)
PHP .ini, PHP .conf (ini, conf)
PHP Laravel (php, inc)
Gettext .po/.pot (po, pot)
Java .properties, InnoSetup .isl (properties, isl)
Java .properties v2, InnoSetup .isl (properties, isl)
Microsoft Windows Resource File .rc (rc)
Microsoft .resx, .resw (resx, resw)
Microsoft .resx, .resw (resx, resw)
Blackberry .rrc (rrc)
Youtube Close Caption .sbv (sbv)
SubRip subtitles .srt (srt)
Apple .strings (strings)
Apple .stringsdict (stringsdict)
Subviewer .sub (sub)
Term Base Exchange .tbx (tbx)
Translation Memory Exchange .tmx (tmx)
Qt Linguist .ts (ts)
Typo3 L10N (xml)
Xliff (xlf, xml, xlif, xliff)
Xliff2 (xlf, xml, xlif, xliff)
XTB (xtb)
Yaml (yml, yaml)</select>
関心ごとの分離
バリュー・オブジェクト(Domain Driven
Design)
ドキュメント・スキーマDB
バリュー・オブジェ
クト
リレーショナル・データベース
エンティティ
設定値のサンプル(カプセル化と関心ごとの分離)
ページ属性
各ページ
アプリケーション名
言語
設定値のセクション
アプリケーショ
ン・コンテキス
ト
日本語
管理画面
ホーム 検索
上映日 上映開始 上映終了 題名 スクリーン番号
個人情報
英語
Management
Console
Home Search
Date SlotStart SlotEnd Title ScreenNumber
Privacy
Dotnet new razor
Visual Studio
Code起動
Ctrl+@
→パネルサイズ
の最大化
Dotnet new –list
Razor Pagesを選
択
appsettings.json
日本語部分 英語部分
個人情報ペー
ジのダミー
データ
appsettings.json
日本語部分 英語部分
個人情報ペー
ジのダミー
データ
ApplicationContextモデルと設定読込
ApplicationContextモデ
ル
PrivacyContentsObject
やHomeContentsObject
のモデル(ページ実装
無し)
Program.csで設定読込
ApplicationContextモデルと設定読込
ApplicationContextモデ
ル
PrivacyContentsObject
やHomeContentsObject
のモデル(ページ実装
無し)
Program.csで設定読込
Layout.chtml
ページの取得
「ホーム」
「検索」「個
人情報」
ヘッダ部分の
描画
ボディとフッ
タ部分の描画
Search.chtmlとSearch.chtml.cs
cs側で設定値
をViewDataに
格納
chtml側で利
用
Index.chtml.csと実行
cs側で設定値を
ViewDataに格納
QueryStringから
設定値を逆引き
してページのタ
イトルを取得
Ctrl+@でターミ
ナル
→dotnet watch
runで実行
ひとまず英語と日本語の動作を確認
Razorのルーティ
ングによって
Indexが呼ばれる
QueryStringで
ページ・リダイレ
クト
SearchModelのコ
ンストラクタで読
み込みする設定値
を英語に変える
オプションズ・パターンの特長を生かすCI
バウンダリー
コンテキスト
特長
Web App, API,
MVC
オプション
ズ・パター
ンの特長
関心ごとの
分離
コントロー
ルの画面描
画の定義
エリアごと
の画面描画
の定義
カプセル化
言語切替機
能(言語の
追加)
言語の追加
Spanishを1行追加
appsettings.json
にスペイン語を追
加
SearchModelのコ
ンストラクタで読
み込みする設定値
をスペイン語に変
える
言語の追加
設定の読込をセク
ションごとでなく全
体に変更する
ApplicationContext
にLanguagesを追加
SearchModelのコン
ストラクタで
Languagesを設定
→ViewDataに設定
言語の追加
ViewData経由で
Languagesを取
得
→選択肢を作成
選択リストを
作成
asp-itemsに設
定するだけ
言語の追加
ViewData経由で
Languagesを取
得
→選択肢を作成
選択リストを
作成
asp-itemsに設
定するだけ
 Optionsパターンはカプセル化と関心ごとの分離が可能
 階層構造の設定値定義ができるのでマイクロサービス、ポリグロット・パーシ
ステンス、ドメイン・ドリブン・デザインと親和性が高い
 グローバリゼーションはパターン・アンド・プラクティスがありますが、PoC
などのモックであればOptionsパターンで軽微に構築できる
 同じ構造のモデルならば「public const string Japanese = “Japanese”;」など
を複数指定することで別々の構造体として生成できる
 その仕組みを使うとセクションごとに読み込まなくとも自動的に別々の構造体
に別々の設定値が読み込まれる
 設定値のセクション定義、読込クラスの名前、利用時の指定が一貫したコー
ディングになるように設計されている
まとめ
レコード型 - C# によるプログラミング入門 | ++C++; // 未確認飛行 C
https://ufcpp.net/study/csharp/datatype/record/
非パブリック、パラメーターなしのコンストラクターが逆シリアル化に使用されない | Microsoft Docs
https://docs.microsoft.com/ja-jp/dotnet/core/compatibility/serialization/5.0/non-public-parameterless-constructors-not-used-for-deserialization
Parameterless struct constructors | Microsoft Docs
https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/proposals/csharp-10.0/parameterless-struct-constructors
ASP.NET Core のオプション パターン | Microsoft Docs
https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/configuration/options?view=aspnetcore-6.0
DDD 指向マイクロサービスの設計 | Microsoft Docs
https://docs.microsoft.com/ja-jp/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/ddd-oriented-microservice
ControllerBase.ViewBag プロパティ (System.Web.Mvc) | Microsoft Docs
https://docs.microsoft.com/ja-jp/dotnet/api/system.web.mvc.controllerbase.viewbag?view=aspnet-mvc-5.2
ViewPage.ViewData プロパティ (System.Web.Mvc) | Microsoft Docs
https://docs.microsoft.com/ja-jp/dotnet/api/system.web.mvc.viewpage.viewdata?view=aspnet-mvc-5.2
"No parameterless constructor found" when trying to deserialize data from Google.Protobuf
https://github.com/protobuf-net/protobuf-net/issues/826
Links
Class ClientBase | .NET client library | Google Cloud
https://cloud.google.com/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.ClientBase
ASP.NET Core の構成 | Microsoft Docs
https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/configuration/?msclkid=d80e714bd0e011ecb654ad0245863624&view=aspnetcore-6.0
ASP.NET Core での依存関係の挿入 | Microsoft Docs
https://docs.microsoft.com/ja-jp/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-6.0
ASP.NET Core での Razor ファイルのコンパイル | Microsoft Docs
https://docs.microsoft.com/ja-jp/aspnet/core/mvc/views/view-compilation?view=aspnetcore-6.0&tabs=visual-studio
Links