简体   繁体   English

Unable to resolve dependencies (有些依赖没有构建)问题

[英]Unable to resolve dependencies ( Some dependencies are not constructed ) issue

In .NET Core, I am getting the issue of dependency resolution.在 .NET Core 中,我遇到了依赖解析问题。 I have the following class hierarchy.我有以下 class 层次结构。

public abstract class TestBaseConfigs
{
      //some base configs
}

public class ChildDfx1Configs : TestBaseConfigs
{
   //some specific child configs.
}

public class ChildDfx2Configs : TestBaseConfigs
{
   //some specific child configs2
}

public interface ITest<T>
{
    void Calculate();
}

public class Dfx1Calc : ITest<ChildDfx1Configs >
{
    void Calculate()   //implemented method from interface
    {
    }

}

public class Dfx2Calc : ITest<ChildDfx2Configs>
{
    void Calculate()   //implemented method from interface
    {
    }
}

var currencyExchangeSettings = Configuration.GetSection("DfxCurrencyExchangeSettings");

var useDfx1CurrencyExchange = currencyExchangeSettings["UseDfx1CurrencyExchange"];

if (Convert.ToBoolean(useDfx1CurrencyExchange))
{
    services.AddScoped<ITest<ChildDfx1Configs>, Dfx1Calc>();  not works.. 
    services.AddScoped<ITest<TestBaseConfigs>, Dfx1Calc>(); //this also doesn't work as well.

         

}

and the constructor of class where the above dependency needed to be passed in.以及 class 的构造函数,其中需要传入上述依赖。

public TranslationFeeManager(IChargesRepository chargesRepository, ITest<TestBase> currencyConversionManager)
{
    _chargesRepository = chargesRepository;
    _currencyConversionManager = currencyConversionManager;
}

Somehow ITest does not resolved.不知何故 ITest 没有解决。 Dont know why.不知道为什么。 What could be the reight solution?什么是正确的解决方案? Can any body help me here?任何人都可以在这里帮助我吗? Thanks.谢谢。

Did you mean Dfx1Calc instead of DfxCalc when adding services?添加服务时,您是指Dfx1Calc而不是DfxCalc吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM