RegisterInstance not working with more than one package

Issue #30 resolved
Andreas Pohl created an issue

I use Spring-Container with Runtime-packages. All is working if I have only one package. Now I have divided my application in 2 dependend packages and get errors on using RegisterInstance<TFunc<IBlaBla>>

I created a simplified test-scenario without runtime-packages, with one package and with two (attached). If you run the one with two packages, you will get an error, because the delegate-function is not called. Where is my fault?

Comments (5)

  1. Stefan Glienke repo owner

    Yay generics... -.-

    The cause is simple: The TFunc<IMES4FServerConnection> of the constructor parameter in unit DSBOProxy.System has a different type info than the TFunc<IMES4FServerConnection> you are using in unit uAppBuilder.

    There is no easy way around to make this work because

    • using an alias will not work (still different type info)

    • declaring a new type for TFunc<IMES4FServerConnection> is not possible (like TMyFactory = type TFunc<IMES4FServerConnection> will cause E2574 Instantiated type can not be used for TYPE'd type declaration)

    • declaring your own anonymous method type will not be accepted by the container. That is because there it no TTypeKind for anonymous methods, they are also tkInterface and thus the generic type name is checked for starting with 'TFunc<', 'TProc<' or 'TPredicate<' to determine if this is a delegate type which is a very poor workaround but the only chance. And since your own anonymous method type would not be recognized as that the container will not allow it to be registered because it does not allow any other types that are interfaces to not have a guid.

    But fortunately the container supports creating factories automatically and out of the box. That means the RegisterInstance is not necessary at all. This is a feature that 1.0 already contains. The container can auto resolve TFunc<T> where T is resolvable and is either an interface or a class.

    BTW the files had no proper Windows line ending but only an LF. You might set that up correctly in your GIT client.

  2. Log in to comment