VContainer icon indicating copy to clipboard operation
VContainer copied to clipboard

Support dynamic registration from open generic type

Open hadashiA opened this issue 3 years ago • 2 comments

#301

If the open generic type is registered, the closed generic type will be dynamically assembled at resolve time.

builder.Register(typeof(IFoo<,>), typeof(Foo<,>))

📝 Usage: https://github.com/Cysharp/MessagePipe/blob/master/src/MessagePipe/ServiceCollectionExtensions.cs#L43-L102

hadashiA avatar Apr 24 '21 17:04 hadashiA

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/hadashia/vcontainer/BeCZQEMCyDrYStHXQN76EX5aXLAt
✅ Preview: https://vcontainer-git-ku-open-generics-hadashia.vercel.app

vercel[bot] avatar Apr 24 '21 17:04 vercel[bot]

Since this approach is only making instances of the closed generic types using reflection it means it won't work with IL2CPP, right? It will only work if code generation is used since it will then generate the code that actually uses those types so they won't be missing in runtime.

igor84 avatar Aug 21 '22 11:08 igor84

I decided to adopt this one. #367

MakeGenericType seems to work in recent Unity. See also the comments.

hadashiA avatar Dec 23 '23 06:12 hadashiA