Skip to content

Commit 28709b4

Browse files
committed
Update readme with newer changes
1 parent 9998522 commit 28709b4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

readme.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ The `ServiceLifetime` argument is optional and defaults to [ServiceLifetime.Sing
4848

4949
> NOTE: The attribute is matched by simple name, so you can define your own attribute
5050
> in your own assembly. It only has to provide a constructor receiving a
51-
> [ServiceLifetime](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.servicelifetime) argument.
51+
> [ServiceLifetime](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.servicelifetime) argument,
52+
> and optionally an overload receiving an `object key` for keyed services.
5253
5354
A source generator will emit (at compile-time) an `AddServices` extension method for
5455
[IServiceCollection](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.iservicecollection)
@@ -160,7 +161,7 @@ static partial class AddServicesExtension
160161
{
161162
public static IServiceCollection AddServices(this IServiceCollection services)
162163
{
163-
services.AddScoped(s => new MyService());
164+
services.TryAddScoped(s => new MyService());
164165
services.AddScoped<IMyService>(s => s.GetRequiredService<MyService>());
165166
services.AddScoped<IDisposable>(s => s.GetRequiredService<MyService>());
166167

@@ -180,10 +181,10 @@ If the service type has dependencies, they will be resolved from the service
180181
provider by the implementation factory too, like:
181182

182183
```csharp
183-
services.AddScoped(s => new MyService(s.GetRequiredService<IMyDependency>(), ...));
184+
services.TryAddScoped(s => new MyService(s.GetRequiredService<IMyDependency>(), ...));
184185
```
185186

186-
Keyed services will emit AddKeyedXXX methods instead.
187+
Keyed services will emit TryAddKeyedXXX methods instead.
187188

188189
## MEF Compatibility
189190

0 commit comments

Comments
 (0)