maui-samples icon indicating copy to clipboard operation
maui-samples copied to clipboard

FlyOutPage Dependency Injection

Open hagaygo opened this issue 3 years ago • 2 comments

Hi,

Trying to apply dependency injection while using FlyOutPage.

In the sample project FlyoutPageSample, I have added a simple class called MyViewModel and added it to the MainPage constructor :

public MainPage(MyViewModel mv) { InitializeComponent(); }

The app will not compile and throws the following error :

Build started... 1>------ Build started: Project: FlyoutPageSample, Configuration: Debug Any CPU ------ 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>Done building project "FlyoutPageSample.csproj" -- FAILED. 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>Done building project "FlyoutPageSample.csproj" -- FAILED. 1>AppFlyout.xaml(11,18): XamlC error XFC0004: Missing default constructor for "FlyoutPageSample.MainPage". 1>Done building project "FlyoutPageSample.csproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I tried looking for a working example of dependency injection while using FlyOutPage and did not find any.

Is it not supported yet ? if it does , can we have a working example for it ?

hagaygo avatar Aug 15 '22 09:08 hagaygo

Look at the repository 👍 https://github.com/dotnet-presentations/dotnet-maui-workshop The workshop describes how to accomplish passing a viewmodel to a page constructor

davefxy avatar Aug 15 '22 18:08 davefxy

Thanks for your answer.

I looked at the slides and example solutions there and did not find any relevant example using FlyOutPage like the official sample project "FlyoutPageSample".

To be more clear , when not using FlyoutPage , the dependency injection works as described/documented.

But when i do use FlyoutPage , the project wont compile and the errors i attached are shown when trying to compile and not on runtime.

So i am asking again , is there a chance that FlyoutPage not supported/missed out on this ? or there is a working example for DI when using FlyoutPage ?

hagaygo avatar Aug 16 '22 07:08 hagaygo