Microsoft.Unity is not Unity.Resolve <ILogger> when my concrete class has two constructors?

I have a specific class loggerthat Microsoft.Unity will allow ILoggerto.

The logger class has two constructors:

1. public logger()
2. public logger(List<BaseLogger> Loggers)

I have a unity section in my web.config file that looks like this:

<unity>
<containers>
  <container>
    <types>

      <type type="MyCompany.Logger.ILogger, MyCompany.Logger"
           mapTo="MyCompany.Logger.logger, MyCompany.Logger">

      </type>
    </types>
   </container>
  </containers>
</unity>

If I remove the constructor specified as 2, the logger class is successfully resolved by Unity. When I add it back, I get this error ...

Dependency resolution failed, type = "MyCompany.Logger.ILogger", name = "(none)". An exception occurred at the time: at resolution. Exception: InvalidOperationException. List`1 has several constructors of length 1. Cannot resolve the ambiguity.

- , web.config, "2.", Unity.Resolve?

+3
1

Unity , .

, , . , InjectionConstructor, . .

, MSDN . . , . , . . , .

+3

Source: https://habr.com/ru/post/1761768/


All Articles