Skip to content

Commit

Permalink
cleanup dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmontemagno committed Jan 10, 2025
1 parent 3cafda2 commit 5b70b33
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
2 changes: 1 addition & 1 deletion Finish/MonkeyFinder/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static MauiApp CreateMauiApp()
builder.Services.AddSingleton<MonkeysViewModel>();

builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();
builder.Services.AddSingleton<DetailsPage>();
return builder.Build();
}
}
4 changes: 3 additions & 1 deletion Part 3 - Navigation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,11 @@ Now that we have our details page in place, we need to register it for routing.

```csharp
builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();

```

> Starting in .NET 9 you no longer need to register Pages with the dependency service for constructor injection to work. By default when we navigate to a new page it will be created an the `MonkeyDetailsViewModel` will be injected as well.

1. Finally, we must inject the view model into our `DetailsPage`. Open the code behind for the page in `DetailsPage.xaml.cs` and change the constructor to the following:

```csharp
Expand Down
4 changes: 3 additions & 1 deletion Part 3 - Navigation/README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ public partial class DetailsPage : ContentPage

```csharp
builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();

```

> Starting in .NET 9 you no longer need to register Pages with the dependency service for constructor injection to work. By default when we navigate to a new page it will be created an the `MonkeyDetailsViewModel` will be injected as well.

3. 最后,我们必须将视图模型注入到我们的 `DetailsPage` 中。 在 `DetailsPage.xaml.cs` 中打开页面背后的代码,并将构造函数更改为以下内容:

```csharp
Expand Down
3 changes: 2 additions & 1 deletion Part 3 - Navigation/README.zh-tw.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ public partial class DetailsPage : ContentPage

```csharp
builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();

```
> Starting in .NET 9 you no longer need to register Pages with the dependency service for constructor injection to work. By default when we navigate to a new page it will be created an the `MonkeyDetailsViewModel` will be injected as well.

3. 最後,開啟 `DetailsPage.xaml.cs` 這個 DetailPage.xaml 所對應的後置程式碼檔案,並將 DetailPage 的建構方法改為如下內容:

Expand Down
2 changes: 1 addition & 1 deletion Part 4 - Platform Features/MonkeyFinder/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
2 changes: 1 addition & 1 deletion Part 5 - CollectionView/MonkeyFinder/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down
2 changes: 1 addition & 1 deletion Part 6 - AppThemes/MonkeyFinder/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static MauiApp CreateMauiApp()


builder.Services.AddTransient<MonkeyDetailsViewModel>();
builder.Services.AddTransient<DetailsPage>();


return builder.Build();
}
Expand Down

0 comments on commit 5b70b33

Please sign in to comment.