[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
Justification = "Parameters to this method are primitive and are trimmer safe.")]
[Event(7, Level = EventLevel.Informational, Keywords = Keywords.ServiceProviderInitialized)]
- private void ServiceProviderBuilt(int serviceProviderHashCode, int singletonServices, int scopedServices, int transientServices)
+ private void ServiceProviderBuilt(int serviceProviderHashCode, int singletonServices, int scopedServices, int transientServices, int closedGenericsServices, int openGenericsServices)
{
- WriteEvent(7, serviceProviderHashCode, singletonServices, scopedServices, transientServices);
+ WriteEvent(7, serviceProviderHashCode, singletonServices, scopedServices, transientServices, closedGenericsServices, openGenericsServices);
}
[UnconditionalSuppressMessage("ReflectionAnalysis", "IL2026:RequiresUnreferencedCode",
int singletonServices = 0;
int scopedServices = 0;
int transientServices = 0;
+ int closedGenericsServices = 0;
+ int openGenericsServices = 0;
StringBuilder descriptorBuilder = new StringBuilder("{ \"descriptors\":[ ");
bool firstDescriptor = true;
transientServices++;
break;
}
+
+ if (descriptor.ServiceType.IsGenericType)
+ {
+ if (descriptor.ServiceType.IsConstructedGenericType)
+ {
+ closedGenericsServices++;
+ }
+ else
+ {
+ openGenericsServices++;
+ }
+ }
}
descriptorBuilder.Append(" ] }");
int providerHashCode = provider.GetHashCode();
- ServiceProviderBuilt(providerHashCode, singletonServices, scopedServices, transientServices);
+ ServiceProviderBuilt(providerHashCode, singletonServices, scopedServices, transientServices, closedGenericsServices, openGenericsServices);
string descriptorString = descriptorBuilder.ToString();
int chunkCount = descriptorString.Length / MaxChunkSize + (descriptorString.Length % MaxChunkSize > 0 ? 1 : 0);
serviceCollection.AddScoped<IFakeMultipleService, FakeDisposableCallbackInnerService>();
serviceCollection.AddTransient<IFakeMultipleService, FakeDisposableCallbackInnerService>();
serviceCollection.AddSingleton<IFakeService, FakeDisposableCallbackInnerService>();
+ serviceCollection.AddScoped(typeof(IFakeOpenGenericService<>), typeof(FakeOpenGenericService<>));
+ serviceCollection.AddTransient<IFakeOpenGenericService<PocoClass>, FakeOpenGenericService<PocoClass>>();
using ServiceProvider provider = serviceCollection.BuildServiceProvider();
EventWrittenEventArgs serviceProviderBuiltEvent = _listener.EventData.Single(e => e.EventName == "ServiceProviderBuilt");
GetProperty<int>(serviceProviderBuiltEvent, "serviceProviderHashCode"); // assert hashcode exists as an int
Assert.Equal(4, GetProperty<int>(serviceProviderBuiltEvent, "singletonServices"));
- Assert.Equal(1, GetProperty<int>(serviceProviderBuiltEvent, "scopedServices"));
- Assert.Equal(2, GetProperty<int>(serviceProviderBuiltEvent, "transientServices"));
+ Assert.Equal(2, GetProperty<int>(serviceProviderBuiltEvent, "scopedServices"));
+ Assert.Equal(3, GetProperty<int>(serviceProviderBuiltEvent, "transientServices"));
+ Assert.Equal(1, GetProperty<int>(serviceProviderBuiltEvent, "closedGenericsServices"));
+ Assert.Equal(1, GetProperty<int>(serviceProviderBuiltEvent, "openGenericsServices"));
Assert.Equal(7, serviceProviderBuiltEvent.EventId);
EventWrittenEventArgs serviceProviderDescriptorsEvent = _listener.EventData.Single(e => e.EventName == "ServiceProviderDescriptors");
" \"serviceType\": \"Microsoft.Extensions.DependencyInjection.Specification.Fakes.IFakeService\",",
" \"lifetime\": \"Singleton\",",
" \"implementationType\": \"Microsoft.Extensions.DependencyInjection.Specification.Fakes.FakeDisposableCallbackInnerService\"",
+ " },",
+ " {",
+ " \"serviceType\": \"Microsoft.Extensions.DependencyInjection.Specification.Fakes.IFakeOpenGenericService`1[TValue]\",",
+ " \"lifetime\": \"Scoped\",",
+ " \"implementationType\": \"Microsoft.Extensions.DependencyInjection.Specification.Fakes.FakeOpenGenericService`1[TVal]\"",
+ " },",
+ " {",
+ " \"serviceType\": \"Microsoft.Extensions.DependencyInjection.Specification.Fakes.IFakeOpenGenericService`1[Microsoft.Extensions.DependencyInjection.Specification.Fakes.PocoClass]\",",
+ " \"lifetime\": \"Transient\",",
+ " \"implementationType\": \"Microsoft.Extensions.DependencyInjection.Specification.Fakes.FakeOpenGenericService`1[Microsoft.Extensions.DependencyInjection.Specification.Fakes.PocoClass]\"",
" }",
" ]",
"}"),