Autofac when using IIndex<X,B> to resolve service throws exception

207
18 августа 2017, 23:26

Итак, у нас есть два класса, реализующих интерфейс IStateRepository: FileRepo and DBRepo (реализация вне контекста). И класс-потребитель:

public class StateBase : IStateAdapter
{
     public StateBase(
         ILogger logger,
         SourceConfiguration source,
         StateConfiguration state,
         IIndex<StorageType, IStateRepository> repoService)
    {      
        _stateStorage = repoService[state.StorageType];
    }
}

Регистрация классов и их зависимостей:

var _builder = new ContainerBuilder();
_builder.RegisterInstance(_logger).As<ILogger>();
_builder.RegisterInstance(config.Source).As<SourceConfiguration>();
_builder.RegisterInstance(config.State).As<StateConfiguration>();
_builder.RegisterType<CsvFileRepository>().Keyed<IStateRepository>(StorageType.File)
    .UsingConstructor(typeof(ILogger), typeof(StateConfiguration));
_builder.RegisterType<MsSqlDataRepository>().Keyed<IStateRepository>(StorageType.Database)
// Register State Adapter
_builder.RegisterType<StateAsID>().Keyed<IStateAdapter>(StateType.ID);
_builder.RegisterType<StateAsRowVersion>().Keyed<IStateAdapter>(StateType.RowVersion);
_builder.RegisterType<StateAsTimeStamp>().Keyed<IStateAdapter>(StateType.TimeStamp);
_builder.RegisterType<StateAsFixedRange>().Keyed<IStateAdapter>(StateType.FixedRange);

Однако когда я пытаюсь отрезолвить реализацию IStateAdapter:

var state = _container.ResolveKeyed<IStateAdapter>(config.Source.LastStateType);

Падает следующий exception

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'BI.Generic.PipeLine.StateAdapters.StateAsRowVersion' can be invoked with the available services and parameters:\r\nCannot resolve parameter 'Scalepoint.BI.Generic.Core.Interfaces.IIndex2[BI.Generic.Core.StorageType,BI.Generic.PipeLine.StateAdapters.IStateRepository] repoService' of constructor 'Void .ctor(Serilog.ILogger, BI.Generic.Core.SourceConfiguration, BI.Generic.Core.StateConfiguration, BI.Generic.Core.Interfaces.IIndex2[BI.Generic.Core.StorageType,BI.Generic.PipeLine.StateAdapters.IStateRepository])'.

READ ALSO
Запись и чтение информации в и из listBox

Запись и чтение информации в и из listBox

Есть 2 textBox'а, один 1 другой второйВ них вписываю информацию в первый "Jule" во второй "June"

345
Проверка хоста C#

Проверка хоста C#

Здравстуйте, есть ip-адреса

245
Итоговый размер aes

Итоговый размер aes

Необходимо узнать размер выходных данных зашифрованных с помощью aes

230
Как правильно работает Thread.Sleep(0)?

Как правильно работает Thread.Sleep(0)?

Правильно ли я понимаю, только когда в while придет false, тогда закончится метод StartWork?

179