Skip to content

Commit

Permalink
Add run app details
Browse files Browse the repository at this point in the history
  • Loading branch information
IEvangelist committed Jul 18, 2024
1 parent ca9e240 commit e4ea1ac
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion docs/core/extensions/dependency-injection-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The abstractions for DI in .NET are defined in the [Microsoft.Extensions.Depende

In .NET, DI is managed by adding services and configuring them in an `IServiceCollection`. After services are registered, as `IServiceProvider` instance is built by calling the `BuildServiceProvider` method. The `IServiceProvider` acts as a container of all the registered services, and it's used to resolve services.

## Create services
## Create example services

Not all services are created equally. Some services require a new instance each time that the service container gets them (_transient_), while others should be shared across requests (_scoped_) or for the entire lifetime of the app (_singleton_). For more information on service lifetimes, see [Service lifetimes](dependency-injection.md#service-lifetimes).

Expand Down Expand Up @@ -101,6 +101,15 @@ All of these services are registered as singletons, although for this sample, it
> [!IMPORTANT]
> In this contrived example, the service lifetimes don't matter, but in a real-world application, you should carefully consider the lifetime of each service.
## Run the sample app

To run the sample app, either press <kbd>F5</kbd> in Visual Studio, Visual Studio Code, or run the `dotnet run` command in the terminal. When the app completes, you should see the following output:

```console
Hello, David!
Goodbye, David!
```

### Service descriptors

The most commonly used APIs for adding services to the `ServiceCollection` are lifetime-named generic extension methods, such as:
Expand Down

0 comments on commit e4ea1ac

Please sign in to comment.