-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Optimize Xamarin Forms DryIoc adapter performance #1074
Comments
@dadhi if you want to join the Slack channel we can easily discuss there what improvements should be made to optimize the DryIoc implementation. The specific function you're pointing to we have a requirement for the ViewModelLocator to construct the ViewModel with an instance of the |
The INavigationService is not a singleton and is specific to a particular page. This means an instance of the nav service must be created, properties set, and then injected into each ViewModel manually. Is there a better way? |
By the way, I am considering making DryIoc the new "official" container of Prism. So any improvements you can make to the implementation the better :) |
Thanks for responding! What I see in this fragment and in other places is using of Service Locator instead of Dependency Injection. Instead of injecting the required service, the container/locator itself is injected, and then the service is Resolved from it. Not so much benefits from DI, more like double work. Ideally, the fragment in question should look like this:
The problem is that current nav service accepts Page as property. DryIoc won't pass Func arguments to properties (at the moment). Then why not to add Page to nav service constructor? As I understood nav service is transient and bound to page? |
For each page that is created, an INavigationService instance must be created and the Page property must be set. Then that INavigationService instance must be injected into the page's ViewModel ctor if the INavigationService interface is defined as a dependency in the VM ctor. I'm not apposed to adding a Page parameter to the ctor as long as it works :) |
At first glance this does seem to work. However, if we add the Page parameter to the ctor, a Page object will always be created even when it's not wanted. Sometimes it needs to be null so that we access the Application's MainPage: https://github.com/PrismLibrary/Prism/blob/master/Source/Xamarin/Prism.Forms/Navigation/PageNavigationService.cs#L492 Now, you'll probably say that to turn off WithAutoConcreteTypeResolution, but we need this in order for other concrete objects to be created when required. Such as the XF NavigationPage. |
Would this be better than what we have now?
|
I have created the simple model here to experiment with. May be wrong though.
It is better to avoid such convention in framework itself. If user wants such magic in the App services, it is his choice. |
You will never win this argument :). If this option is turned off, Prism breaks and is completely unusable as none of the ViewModels would be created. |
Just a heads up that I am working on DryIoc v3 which will released in upcoming weeks. May expect perf improvements and removal of some integration pain points. |
Great to hear! |
Hey @dadhi, I was wondering why this code doesn't work when providing a serviceKey:
Is this supported? |
Never mind, I think I understand what is going on and why this doesn't work. The serviceKey is not the parameter name when the INavigationService is being resolved as a dependency. |
Ok, I need to run it to figure out. Btw, the next DryIoc v3 will support (already in preview) the |
In your sample when resolving
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi, I am an author of DryIoc.
Looking at code, it seems over-complecated and therefore minimizes the wins provided by DryIoc performance.
The goal of this issue (for me) is to gather more info about IoC conventions used by Prism Application. At the moment I am unable to use Xamarin (dev license issues), and cannot PR directly. But I can do educated guesses :-) and list the ideas for improvements here. Then me, when I have license, or may be someone else may try them.
The text was updated successfully, but these errors were encountered: