Static reflection binder?

60 views
Skip to first unread message

Eris Koleszar

unread,
Jul 27, 2017, 12:56:29 PM7/27/17
to StrangeIoC
Hi,

I am working on a project using Strange and we are in the practice of creating many contexts in a more modular fashion. Some of these right now are tied to Unity scenes and every time the scene is loaded, all the reflection for the classes bound in those contexts happens again. Is there a reason there couldn't be (in addition to the regular binder) a ReflectionBinder that is static and shared across contexts for mapping purposes only?

thanks,
Eris

PS Thanks for everyone's hard work in making this framework! <3

wcorwin

unread,
Jul 27, 2017, 1:03:23 PM7/27/17
to StrangeIoC
The reflections should all be cached. ReflectionBinder won't reflect a class more than once.

If you're instantiating a new ReflectionBinder, it won't have a cache. Could you create a simple test project showing this for me? You might be right that there's room for a bit of improvement here for a project using many contexts.



Eris Koleszar

unread,
Jul 27, 2017, 1:20:32 PM7/27/17
to StrangeIoC
I can create that project for you sometime this week when I have a minute (sorry, we're under some deadlines at the moment). For contexts whose lifetimes are tied to the scene (created and destroyed on scene load/unload), we've put logs in the Get(Type type) method of ReflectionBinder and it doesn't matter how many times we've loaded the scene previously, we'll get a log that the binding is null and it's creating a raw binding the first time Get() is called for that Type.

wcorwin

unread,
Jul 27, 2017, 1:44:43 PM7/27/17
to StrangeIoC
I think it's pretty reasonable to make ReflectionBinder Cross Context. We're currently spinning up a new one for each Injector. We want injectors to be separate, but they could all point to the same cross context reflection binder, for sure. That sounds easy in theory, but since InjectionBinder is what's responsible for fulfilling bindings, we need to spin up the ReflectionBinder manually and then map it cross context (and try to get it when an injectionBinder comes alive). The latter half of that sentence doesn't exist. I'd recommend making changes in CrossContextInjectionBinder to do this. If you're right, this is a straightforward (although on the larger side) unit test. I'm really squeezed on time until next week, but if you can show me some proof of the issue and confirm the fix with tests, I'd be happy to review a PR! It'd be good to have ReflectionBinder managed within strange itself, as opposed to being a raw class we new up.

Hope this helps. Let me know where you need more clarity? And thanks for pointing this out!

Eris Koleszar

unread,
Aug 3, 2017, 7:13:08 PM8/3/17
to StrangeIoC
It'd be good to have ReflectionBinder managed within strange itself, as opposed to being a raw class we new up.

By this do you mean that you would want the IReflectionBinder mapped to the ReflectionBinder Cross Context and actually inject it into the CrossContextInjectionBinder somehow?  I managed to get a single ReflectionBinder that lives in the firstContext working, but it's more based on the way that the CrossContextBinder is being passed to subsequent CrossContext instances. If submitting a PR would be easier, I could just do that.

wcorwin

unread,
Aug 3, 2017, 8:09:50 PM8/3/17
to StrangeIoC
Yup, just submit a PR, we can continue convo there.
Reply all
Reply to author
Forward
0 new messages