-
-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add open generic registration api and resolve feature #367
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/hadashia/vcontainer/42FG2b3uqBQcKJysb5xMwiRxGK2h |
Thanks for working on it! |
Hey! Can you tell me if there is any progress on this issue? |
@DenisPimenov Sorry for the delay in replying. First of all, I would like to thank you. I think this implementation is not bad. However, I would like to confirm two points.
As pointed out here, in an IL2CPP environment, classes that are not statically referenced will probably be omitted. If this problem cannot be solved, there is probably a problem. Second, in some use cases like MessagePipe, So, my I understand is that, there are two ways to support generic types.
If either or both of these are to be implemented, API conflicts need to be avoided. ( However, both 1 and 2 probably have IL2CPP issues... |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@hadashiA I will try different builds with il2cpp and report the results in a few days. |
Is this still happening? |
Perhaps, the full generic sharing in Unity 2022.1 allows the following to work: var t1 = typeof(GenericClass<>).MakeGenericType(typeof(int));
var i1 = (GenericClass<int>)Activator.CreateInstance(t1);
var t2 = typeof(GenericClass<>).MakeGenericType(typeof(ClassA));
var i2 = (GenericClass<ClassA>)Activator.CreateInstance(t2);
var t3 = typeof(GenericClass<>).MakeGenericType(typeof(StructA));
var i3 = (GenericClass<StructA>)Activator.CreateInstance(t3);
var t4 = typeof(GenericStruct<>).MakeGenericType(typeof(int));
var i4 = (GenericStruct<int>)Activator.CreateInstance(t4);
var t5 = typeof(GenericStruct<>).MakeGenericType(typeof(ClassA));
var i5 = (GenericStruct<ClassA>)Activator.CreateInstance(t5);
var t6 = typeof(GenericStruct<>).MakeGenericType(typeof(StructA));
var i6 = (GenericStruct<StructA>)Activator.CreateInstance(t6); So this PR should probably work fine, as long as it's Unity 2022.1 or later. I'd like to refine the API a bit more and merge this functionality. |
# Conflicts: # VContainer/Assets/VContainer/Tests/Fixtures.cs
Hi. It has been a long time since opening PR. I have synchronized with master, but the tests are not passing. I will fix them. |
…as AsSelf and AsImplementedInterfaces Optimize type cache calls
Hi! I fixed all the tests and fixed singleton resolution when the service is configured with multiple implementation types. |
@DenisPimenov |
@hadashiA I have synchronized with master, but it has compilation errors |
Can you fix them? |
registration = null; | ||
return false; | ||
} | ||
|
||
public bool Exists(Type type) => hashTable.TryGet(type, out _); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public bool Exists(Type type) => hashTable.TryGet(type, out _); | |
public bool Exists(Type type) | |
{ | |
if (type.IsConstructedGenericType) | |
{ | |
type = RuntimeTypeCache.OpenGenericTypeOf(type); | |
} | |
return hashTable.TryGet(type, out _); | |
} |
I tested out your implementation in my project and ran into an issue here.
Exists doesn't behave correctly and returns false when checking registered open generics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I forgot the scopes tests and missed that error. I'll add them and your fix as soon as the compilation errors in the master branch are fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I resolve IEnumerable<OpenGenericInterface> or IReadOnlyList<OpenGenericInterface>, I get an empty list. I expect to return me a list for all classes that are registered as this open generic interface.
Additionally in regard to that, I suggest to add tests for resolving multiple instances of an interface.
Oh . . I see. |
Hi! I try to implement open generic feature #301. If you have time to look and tell me what can be changed or improved I can do it