CommunityToolkit / MVVM-Samples

Sample repo for MVVM package
Other
1.11k stars 222 forks source link

Blazor Sample Project #123

Open gragra33 opened 1 year ago

gragra33 commented 1 year ago

I have ported the Xamarin project to a Blazor project with minimal changes. Project can be found here: gragra33 / MvvmSampleBlazor

Pinox commented 1 year ago

Hi @gragra33

Question if u do not mind. Is there a way to add static instance such as:

/// <summary>
/// Gets the current <see cref="App"/> instance in use
/// </summary>
public new static App Current => (App)Application.Current;

so that we can use it with an easy IFilesService filesService = App.Current.Services.GetService();

instead of DI constructor injection or page injection in Blazor ?

gragra33 commented 11 months ago

@Pinox Sorry for the late reply as I was not watching the issues for this Microsoft repo.

The IFilesService interface allows us to abstract the implementation to any implementation. The sample project supports more than one platform as each has a different method of accessing the files.

For your own implementation, there is nothing stopping you from making a bound reference to your implementation in that manny but then you lose the flexibility if you decide to support more than one implementation in the future.