簡體   English   中英

Structuremap和ASP.NET核心

[英]Structuremap and ASP.NET core

我正在使用ASP.NET核心,我正在嘗試將結構圖用於我的IoC,但我似乎遇到了一些問題。 當我編寫一個直接在structuremap中的單元測試時,一切正常。 當我將配置打印到文件時,我可以看到我的設置確實正確地注冊了所有內容。

然而,人口似乎給我帶來了麻煩。

我正在嘗試使用StructureMap.Microsoft.DependencyInjection但我在構建時遇到錯誤:

無法解析依賴關系結構圖> = 4.4.0。

我在我的項目中安裝了StructureMap 4.4.1,包括我將StructureMap.Microsoft.DependencyInjection庫安裝到(我的Web API項目)的項目。

所以,然后我將文件從github上的項目中取出並加載到我的解決方案中,並刪除了nuget包,但由於某種原因它無法正常工作。

這是一個帶有相關文件的plunker

理想情況下,我寧願使用nuget包來執行此操作,但是當我已經安裝了實際的依賴項時,我從未遇到過依賴性問題。

編輯:更多細節

當我將container.WhatDoIHave()的結果寫入文件時,我的類都正確顯示t0是structmap的一部分,但是當我運行container.AssertConfigurationIsValid(); 當我收到WhatDoIHave()報告的正確定義的錯誤時

這是我的配置方法的樣子

    public IServiceProvider ConfigureIoC(IServiceCollection services)
    {
        var container = new Container();

        container.Configure(config =>
        {
            // scan the webapi to register all the controllers
            config.Scan(scan =>
            {
                scan.TheCallingAssembly();
                scan.WithDefaultConventions();
            });

            //this is an IoC configuration in another library that 
            //   ties together a bunch of class libraries so they 
            //   don't all have to be in my web project
            IoC.BootStrapper.Configure(config, "MembershipReboot");
        });

        System.IO.File.WriteAllText(@"C:\users\{me}\documents\structuremapTest.txt", container.WhatDoIHave());

        container.AssertConfigurationIsValid();

        //Populate the container using the service collection
        container.Populate(services);

        return container.GetInstance<IServiceProvider>();
    }

將“StructureMap”包重命名為“structuremap”,似乎與NuGet套管有些奇怪的問題。

干杯:)

在StructureMap.Microsoft.DependencyInjection問題跟蹤器上查看此問題:

依賴結構圖> = 4.3.0無法解析 https://github.com/structuremap/StructureMap.Microsoft.DependencyInjection/issues/17

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM