Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(DI): Clarify DI docs #1499

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,21 @@ Dependency Injection (DI) is an important design pattern for building loosely-co
}
}
```
* For the dependency injection framework to handle instantiation of the service as a constructor argument, you must also register your view model with the `IServiceCollection`:
* If you are using not using [navigation](xref:Overview.Navigation), you have to register the view model to `IServiceCollection`, but we recommend using navigation and not manually register the view model as a service:
```cs
private IHost Host { get; } = BuildAppHost();

private static IHost BuildAppHost()
{
return UnoHost
{
return UnoHost
.CreateDefaultBuilder()
.ConfigureServices(services =>
{
// Register your services
services.AddSingleton<IProfilePictureService, ProfilePictureService>();
{
// Register your services
services.AddSingleton<IProfilePictureService, ProfilePictureService>();
// Register view model
services.AddTransient<MainViewModel>();
})
})
.Build();
}
```
Expand Down