XAM-Consulting / FreshMvvm.Maui

MIT License
44 stars 10 forks source link

Error registering FreshMvvm with MauiApp builder #4

Closed behl1anmol closed 2 years ago

behl1anmol commented 2 years ago

Hello,

I am registering FreshMvvm with the MauiApp builder in MauiProgram.cs as follows:

builder.Services.UseFreshMvvm();

This gives an error:

'IServiceCollection' does not contain a definition for 'UseFreshMvvm' and the best extension method overload 'StartUpExtensions.UseFreshMvvm(MauiApp)' requires a receiver of type 'MauiApp'

FreshMvvm_Error

Following is my configuration:

Everything seems to work fine on FreshMvvm (0.0.1) but upgrading to FreshMvvm (0.0.2) gives the error.

Thanks & Regards, Anmol Behl

NielsKnaap commented 2 years ago

@behl1anmol I ran into the same problem. It seems that the extension UseFreshMvvm has been changed.

This adjustment was probably made after the tip that can be seen in the next issue issue 1 .

The updated class looks like this: public static void UseFreshMvvm(this MauiApp app) { DependancyService.RegisterServiceProvider(app.Services.GetService<IServiceProvider>()); }

And can be used in the following way (MauiProgram.cs): var app = builder.Build(); StartUpExtensions.UseFreshMvvm(app); return app;

The strange thing is, that these changes do not exist in this repository.

rid00z commented 2 years ago

Thanks @NielsKnaap. You are correct, a change has been made based on this recomendation. The source code with this change is now in the repo.