Типы регистров Unity не создаютсяC#

Место общения программистов C#
Anonymous
Типы регистров Unity не создаются

Сообщение Anonymous »

Я использую Unity в качестве IoC. Мне нравится регистрировать некоторые классы в контейнере с помощью RegisterTypes следующим образом:

Код: Выделить всё

container.RegisterTypes(
AllClasses.FromAssembliesInBasePath(),
WithMappings.FromAllInterfaces,
WithName.TypeName,
WithLifetime.PerResolve
);
Но типы не создаются. Мой класс интерфейса:

Код: Выделить всё

namespace Taschenrechner
{
public interface IBerechne
{
int Berechnen(Formel formel);
}
}
И мои классы:

Код: Выделить всё

class Addition : IRechenoperation
{
public char Operator
{
get
{
return '+';
}
}

public int Berechnen(int operand1, int operand2)
{
return operand1 + operand2;
}
}

class Subtraktion : IRechenoperation
{
public char Operator
{
get
{
return '-';
}
}

public int Berechnen(int operand1, int operand2)
{
return operand1 - operand2;
}
}
И конструктор, в который мне нравится внедрять эти типы, выглядит следующим образом:

Код: Выделить всё

    public Parser(Formel formel,IRechenoperation[] rechenoperationen)
{
this.ergebnisformel = formel;
this.rechenoperationen = rechenoperationen;
}
Когда я выполняю код, rechenoperationen всегда представляет собой пустой массив.

Подробнее здесь: https://stackoverflow.com/questions/331 ... -instanced

Вернуться в «C#»