@@ -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
5354A 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
180181provider 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