0

The following code gives the error 'Incomplete registration for type: TPair<System.string,System.string>' but for the life of me I can't figure out what is missing.
I even tried registering String.

var Container:=TContainer.Create;
try
  Container.RegisterType<TPair<String,String>>().InjectConstructor(['A','B']);
  Container.Build;
  var A:=Container.Resolve<TPair<String,String>>;
  OutputDebugString(PChar(A.Key));
finally
  Container.Free;
end;
2
  • Think I have found it. I think it is because TPair<> is a record and not a class. Jan 30 at 11:19
  • That's what the code that raises the error says: if model.ComponentType.TypeKind = tkClass then Jan 30 at 13:37

1 Answer 1

1

Simply do:

Container.RegisterInstance(TPair<string,string>.Create('A', 'B'));

That will let the container know about TPair<string,string> which has those given Key and Value.

2
  • I dumbed it down for the example but I was really trying to resolve a named list of factories so it would be more like TPair<String,IMyFactory>().InjectConstructor(['Type1Name','MyFactoryForType1']); Jan 31 at 14:04
  • Then you should modify your question - one can only answer what has been asked and not what actually was meant by the questioner. Also, you do realize that a TPair<String,IMyFactory> cannot be filled with two strings, yes? Jan 31 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.