-
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
Shell pages cannot work with DI #3147
Comments
This is more a DataTemplate enhancement then being shell specific Making this code work with IServicePRovider would mean that Shell would now create pages via DI container
And then there's a little bit of extra work to make the global routes work with IServiceProvider |
I believe you are right, but anyway this needs to be fixed as it is the central part of the project. Or if you have an alternative I don't know. |
Maybe you can use RouteFactoring for that. It will allow you to create your page in a more complex way. Isn't ideal but can be a workaround. |
Could you give me an example? |
@PureWeen I'm interested in taking a crack at this, unless you think it's something that requires work from the regular team. |
Yes, I did a live code session where a cover this approach, we are talking in Portuguese but you can take the code as a reference. |
@brunck go for it! I haven't dug into this too much yet so I'm not sure how tricky it'll be or won't be. I could also be wrong with my thinking here :-) |
@PureWeen Thanks. Your comment makes sense, the problem I'm running into is that when the ElementTemplate constructor you mention is getting invoked, it seems to be before anything like the IApplication is getting set up with the MauiContext with the IServiceProvider that has what we need, etc. There is an IServiceProvider potentially available that we can shove in there via ProvideValue, but it's not the IServiceProvider that we need; it has things like IXamlTypeResolver in it. |
Just now i realize, what you want to say, but this is not a workaround for me, i'm using yet DI in Xamarin Forms but injecting in Page constructor with : BindingContext = Start.GetService(), but it's a good replacement for my approach |
Description
Steps to Reproduce
Expected Behavior
Application starts fine
Actual Behavior
System.MissingMethodException: 'Cannot dynamically create an instance of type 'MauiProject.Pages.LoginPage'. Reason: No parameterless constructor defined.'
Basic Information
Reproduction Link
https://github.com/osnipezzini/MauiShell
The text was updated successfully, but these errors were encountered: