Azure

Azure App Configurationを.NET6のサンプルで試してみる。

はじめに

Azure App Configurationは、アプリケーションの設定値などを一括に管理するものです。アプリケーションは、コンテナーであったり、Web Appsだったり場所に限らず利用可能です。

とりあえずApp Configurationを触ってみたい人向けです。コードを書くことはしません。

今回はWeb Appsのサンプルが用意されているので、試してみたいと思います。

App Configurationについてはドキュメントが用意されていますが、今回はWeb Appsのサンプルが用意されているので、試してみたいと思います。

日本語のドキュメントは.NET6に関しては記述があないので英語のドキュメントを見ます。

Azure App Configuration documentation | Microsoft Learn
Azure App Configuration documentation | Microsoft Learn

Learn how to use Azure App Configuration, a managed service that helps developers centralize their a ...

docs.microsoft.com

サンプルはGithubにあります。

AppConfiguration/examples/DotNetCore/WebDemoNet6 at main · Azure/AppConfiguration · GitHub
AppConfiguration/examples/DotNetCore/WebDemoNet6 at main · Azure/AppConfiguration · GitHub

Questions, feedback and samples for Azure App Configuration service - AppConfiguration/examples/DotN ...

github.com

前提条件

  • Visual Studio 2022 (2019)
What's new in Visual Studio docs - Visual Studio (Windows) | Microsoft Learn
What's new in Visual Studio docs - Visual Studio (Windows) | Microsoft Learn

Discover recent changes in the Visual Studio documentation, including updated articles about getting ...

visualstudio.microsoft.com

  • ,NET6 SDK
Download .NET (Linux, macOS, and Windows) | .NET
Download .NET (Linux, macOS, and Windows) | .NET

Free downloads for building and running .NET apps on Linux, macOS, and Windows. Runtimes, SDKs, and ...

dotnet.microsoft.com

  • Web Apps(.NET6)は事前に構築されている
  • Visual Studioの使い方

App Configuration

最初にApp Configurationを作成します。

必要事項を入力します。

  • Resource name:任意
  • 場所:任意
  • Pricing tier:無料でも問題ありません

ネットワークはそのまま

作成します。

Web Apps

事前に作成したWeb Appsの設定を行います。

App ConfigurationがWeb Appsからのアクセスを許可するためにマネージドIDを許可します。

App Configurationの設定

App Configurationを開き、アクセス制御を開きます。

メンバー→アクセスの割り当て先:マネージドIDを選択します。

メンバーを選択します。

マネージドIDを有効したWeb Appsを選択してApp Configurationデータ閲覧者で登録します。

登録されていること確認します。

 

 

App Configurationにキーを設定します。

Configuration Explorerを開き登録します。

  • Key:WebDemo:Settings:Messages
  • Value:これは格納されたデータです

Access KeysからConnection Stringをコピーしておきます。

以上で、App Configuration側の設定は完了です。

Web Appsの設定

アプリケーション設定に追加します。

  • ConnectionStoring:上記でコピーしたConnection Storing

これでWeb Appsの設定は完了です。

アプリケーションのデプロイ

下記からZipでダウンロードしてきます。

GitHub - Azure/AppConfiguration: Questions, feedback and samples for Azure App Configuration service
GitHub - Azure/AppConfiguration: Questions, feedback and samples for Azure App Configuration service

Questions, feedback and samples for Azure App Configuration service - Azure/AppConfiguration

github.com

AppConfiguration-main\examples\DotNetCore\WebDemoNet6を開きます。

拡張子、slnのファイル(Visual Studio Solusion)を開きます。

特にコードをいじることなくWeb Appsにデプロイします。

デプロイ完了後にブラウザが開きアクセスされます。

App Configurationに設定した値が表示されれば成功です。

まとめ

App Configurationを実際に動作させるためだけのサンプルで試してみました。App Configurationの挙動を知りたい、使ってみたいけどコードは全く分からない人向けですが、卓上で見てるだけよりはわかると思います。

チュートリアルあるでは、ここに追記、追加など書かれていますが試してみても動かないなどコードが書けない人にとっては難解です。サンプルを活用しましょう。

このようなサンプルはGithubに沢山あります、ドキュメントから参照されていない場合も多いので検索すると出てくる場合が多いですので探してみてください。

-Azure
-