Replies: 6 comments 11 replies
-
Hello, I am using this class here. Unfortunately, I don't know of any other option |
Beta Was this translation helpful? Give feedback.
-
You have to register all of your Views/Viewmodels/Services when building the Maui application on |
Beta Was this translation helpful? Give feedback.
-
Another way:
|
Beta Was this translation helpful? Give feedback.
-
To expand on the MauiProgram static method solution from @ExtSolTech, here's what I'm doing currently. This lets the object still be testable. public class BookmarkButtonImageConverter : IValueConverter
{
private readonly IBrowsingDatabase _browsingDatabase;
// capitulate to XAML and provide a parameterless constructor that mimics DI
public BookmarkButtonImageConverter()
: this(MauiProgram.Services.GetRequiredService<IBrowsingDatabase>())
{
}
// actual good DI constructor, testable
public BookmarkButtonImageConverter(IBrowsingDatabase browsingDatabase)
{
_browsingDatabase = browsingDatabase;
}
|
Beta Was this translation helpful? Give feedback.
-
I was wondering about this and I remember seeing that in Shell you can declare pages that are "wired" by dependency injection: and the constructor of
What makes this behavior possible is Do you think it would be possible to set up an extension to autowire a contentView from Xaml? Is this recommended, or is it not really what MAUI expects? |
Beta Was this translation helpful? Give feedback.
-
I'd love some DI support with For now I'll have to go with the above mentioned workaround with a static |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
how would one access a registered
ViewModel
in aContentView
?for
ContentPage
the following works just fineBeta Was this translation helpful? Give feedback.
All reactions