shunsuke-kawai / netcore_TestFunctions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

前提

開発環境(関係ありそうなヤツだけ抜粋)

Microsoft Visual Studio Enterprise 2017
Version 15.9.4
VisualStudio.15.Release/15.9.4+28307.222
Microsoft .NET Framework
Version 4.7.03056
インストールされているバージョン:Enterprise

ASP.NET and Web Tools 2017 15.9.04012.0
ASP.NET Core Razor Language Services 15.8.31590
ASP.NET Web Frameworks and Tools 2017 5.2.60913.0
Azure App Service Tools v3.0.0 15.9.03024.0
Azure Functions と Web ジョブ ツール 15.9.02046.0
Common Azure Tools 1.10
Microsoft Azure Tools 2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10730.2
NuGet パッケージ マネージャー 4.6.0

DI

他チーム(Functionsでない処理など)との平仄合わせ、共通化のために下記を参考にDIしようとしている。
https://blog.wille-zone.de/post/dependency-injection-for-azure-functions/
Nuget : Willezone.Azure.WebJobs.Extensions.DependencyInjection

問題

現象

下記のようなスタートアップ処理があるが .netcore v2.1 の Function を実行しても処理が走らない

using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using netcore_v2_1_TestFunctions;
using netcore_v2_1_TestFunctions.Services;
using System.IO;
using Willezone.Azure.WebJobs.Extensions.DependencyInjection;

[assembly: WebJobsStartup(typeof(Startup))]
namespace netcore_v2_1_TestFunctions
{
    public class Startup : IWebJobsStartup
    {
        public void Configure(IWebJobsBuilder builder) =>
           builder.AddDependencyInjection(ConfigureServices);

        private void ConfigureServices(IServiceCollection services)
        {
            var configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();

            services.AddSingleton(configuration);
            services.AddSingleton<IMyService, MyService>();
        }
    }
}

回避策

疑問

  • こんなことをやってやらないといけないのか?
  • extensions.json にはバージョンも持ってるみたい(これが食い違っても実行はできたが気持ち悪い
  • この他の extension が増えた場合、逐次 v2.0 でビルド ⇒ extensions.json をコピー ⇒ v2.1 に戻す みたいな手順をやらないといけない?

その他参考リンク

Startup は別にして .NET Standard 2.0 で作れってこと?
Azure/Azure-Functions#1016 (comment)

This is a known issue we're addressing. In the meantime, one of the common ways to workaround the issue is to implement the startup in a separate project (targeting .NET Standard 2.0).

About


Languages

Language:C# 100.0%