「[[Open棟梁 wiki>https://opentouryo.osscons.jp]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-[[戻る>機能一覧 - 対応する処理方式と、そのサンプル#lc433e15]]
--[[共通の初期化処理]]
--.NET Core版の初期化処理

*目次 [#w0fa0eca]
#contents

*概要 [#k3b33c11]
.NET Core対応で初期化処理が必要になった点が幾つかあるのでメモ。

*詳細 [#g4621cf0]

**共通 [#k0d5bb2d]

***GetConfigParameter [#n7221dba]
[[GetConfigParameterクラスで、appsettings.jsonを使用できるようにする初期化処理>https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Frameworks/Infrastructure/Public/Util/GetConfigParameter.cs#L71]]。

-ASP.NET Core
 public Startup(IHostingEnvironment env, IConfiguration config)
 {
   ...
   // configの初期化
   GetConfigParameter.InitConfiguration(config);

-ASP.NET Core以外
 // configの初期化
 GetConfigParameter.InitConfiguration("appsettings.json");

***... [#x01f4a01]

***その他 [#z67554d2]
テンプレートのProgram.csを参考にする。
-https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Samples4NetCore/Legacy/Bat_sample/SimpleBatch_sample/Program.cs

**ASP.NET Core [#t10144e2]

***HttpContext.Current [#z3c9df05]
HttpContext.Currentを使用可能にする。

-Startup.Configure
 // HttpContextのマイグレーション用
 app._UseHttpContextAccessor();

-Startup.ConfigureServices
 // HttpContextのマイグレーション用
 services._AddHttpContextAccessor();

※ 利用の際は、

 MyHttpContext.Current.Session

>等として利用する。

***カレント・ディレクトリ [#y1939e2f]
-ASP.NET Coreでは、[[Docker対応]]などで、相対パスを使用するケースが増えてきた。
-そこで、必要に応じて以下の様に、カレント・ディレクトリを変更する。

 // カレント・ディレクトリを変更する。
 Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

***... [#gdc7545b]

***その他 [#u3f15105]
テンプレートのProgram.csやStartup.csを参考にする。
-https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Samples4NetCore/Backend/MVC_Sample/MVC_Sample/Startup.cs
-https://github.com/OpenTouryoProject/OpenTouryo/blob/develop/root/programs/CS/Samples4NetCore/Backend/MVC_Sample/MVC_Sample/Program.cs

***... [#gdc7545b]

IP:210.234.63.131 TIME:"2021-05-11 (火) 10:45:45" REFERER:"https://opentouryo.osscons.jp/index.php?cmd=edit&page=.NET%20Core%E7%89%88%E3%81%AE%E5%88%9D%E6%9C%9F%E5%8C%96%E5%87%A6%E7%90%86" USER_AGENT:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS