CommunityToolkit / MVVM-Samples

Sample repo for MVVM package
Other
1.15k stars 224 forks source link

MVVM Toolkit Sample App - Reddit Service example wrongly uses IOC class #95

Open xEsteem opened 2 years ago

xEsteem commented 2 years ago

In the samples app, in the Putting Things Together section, the example follows a process whereby services are created, registered in the app.xaml.cs and then injected into the viewmodels via constructor injection.

On the Reddit Service example the SubredditWidgetViewModel gets the IRedditService from the IOC.Default instance

/// <summary>
/// Gets the <see cref="IRedditService"/> instance to use.
/// </summary>
private readonly IRedditService RedditService = Ioc.Default.GetRequiredService<IRedditService

The rest of the sample app doesnt mention really the IoC class at all, and the service is definitely not registered with it in the examples. In fact further down its registered in the app.xaml.cs.

This example should be reworked slightly to accept the IRedditService via constructor injection, like the PostWidgetViewModel. Similarly, the SubredditWidgetViewModel should also be shown to be registered with the service collection too, for consistency