< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Configuration.ServiceModelServiceCollectionExtensions
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Configuration/ServiceModelServiceCollectionExtensions.cs
Line coverage
98%
Covered lines: 67
Uncovered lines: 1
Coverable lines: 68
Total lines: 117
Line coverage: 98.5%
Branch coverage
94%
Covered branches: 17
Total branches: 18
Branch coverage: 94.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
AddServiceModelServices(...)94.44%181898.27%
AddServicesForFederation(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Configuration/ServiceModelServiceCollectionExtensions.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Linq;
 6using CoreWCF.Channels;
 7using CoreWCF.Description;
 8using CoreWCF.Dispatcher;
 9using CoreWCF.IdentityModel;
 10using CoreWCF.IdentityModel.Configuration;
 11using CoreWCF.IdentityModel.Tokens;
 12using Microsoft.AspNetCore.Authorization;
 13using Microsoft.AspNetCore.Hosting.Server;
 14using Microsoft.Extensions.DependencyInjection;
 15using Microsoft.Extensions.DependencyInjection.Extensions;
 16
 17namespace CoreWCF.Configuration
 18{
 19    public static class ServiceModelServiceCollectionExtensions
 20    {
 21        private const string IISHttpServerTypeName = "Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer";
 22
 23        public static IServiceCollection AddServiceModelServices(this IServiceCollection services)
 24        {
 61325            if (services == null)
 26            {
 027                throw new ArgumentNullException(nameof(services));
 28            }
 61329            services.AddSingleton<WrappingIServer>();
 8731030            for (int i = 0; i < services.Count; i++)
 31            {
 4304232                if (services[i].ServiceType == typeof(IServer))
 33                {
 61834                    if (services[i].ImplementationType != null)
 35                    {
 57636                        if (services[i].ImplementationType.FullName.Equals(IISHttpServerTypeName))
 37                        {
 38                            // Don't wrap IISHttpServer as there isn't a console app to discover any thrown exception at
 39                            continue;
 40                        }
 41
 57642                        Type implType = services[i].ImplementationType;
 5039443                        if (!services.Any(d => d.ServiceType == implType))
 44                        {
 51345                            services.AddSingleton(implType);
 46                        }
 57647                        services[i] = ServiceDescriptor.Singleton<IServer>((provider) =>
 57648                            {
 47349                                var originalIServer = (IServer)provider.GetRequiredService(implType);
 47350                                WrappingIServer wrappingServer = provider.GetRequiredService<WrappingIServer>();
 47351                                wrappingServer.InnerServer = originalIServer;
 47352                                return wrappingServer;
 57653                            });
 54                    }
 4255                    else if (services[i].ImplementationInstance != null)
 56                    {
 4057                        object implInstance = services[i].ImplementationInstance;;
 4058                        Type implType = implInstance.GetType();
 255259                        if (!services.Any(d => d.ServiceType == implType))
 60                        {
 4061                            services.AddSingleton(implType, implInstance);
 62                        }
 4063                        services[i] = ServiceDescriptor.Singleton<IServer>((provider) =>
 4064                        {
 4065                            var originalIServer = (IServer)provider.GetRequiredService(implType);
 4066                            WrappingIServer wrappingServer = provider.GetRequiredService<WrappingIServer>();
 4067                            wrappingServer.InnerServer = originalIServer;
 4068                            return wrappingServer;
 4069                        });
 70                    }
 71                }
 72            }
 61373            services.AddSingleton<ServiceBuilder>();
 118574            services.AddSingleton<IServiceBuilder>(provider => provider.GetRequiredService<ServiceBuilder>());
 118675            services.AddSingleton<IServiceBehavior>(provider => provider.GetRequiredService<ServiceAuthorizationBehavior
 61376            services.AddSingleton(provider =>
 61377            {
 57178                ServiceAuthorizationBehavior serviceAuthorizationBehavior = new();
 57179                ServiceAuthorizationManager manager = provider.GetService<ServiceAuthorizationManager>();
 57180                if (manager != null)
 61381                {
 482                    serviceAuthorizationBehavior.ServiceAuthorizationManager = manager;
 61383                }
 57184                IServiceScopeFactory serviceScopeFactory = provider.GetService<IServiceScopeFactory>();
 57185                serviceAuthorizationBehavior.ServiceScopeFactory = serviceScopeFactory;
 57186                return serviceAuthorizationBehavior;
 61387            });
 61388            services.TryAddSingleton(typeof(IServiceConfiguration<>), typeof(ServiceConfiguration<>));
 61389            services.TryAddSingleton<IDispatcherBuilder, DispatcherBuilderImpl>();
 61390            services.AddSingleton(typeof(ServiceConfigurationDelegateHolder<>));
 61391            services.AddSingleton<AllServicesConfigurationDelegateHolder>();
 61392            services.AddScoped<ReplyChannelBinder>();
 61393            services.AddScoped<DuplexChannelBinder>();
 61394            services.AddScoped<InputChannelBinder>();
 61395            services.AddScoped<ServiceChannel.SessionIdleManager>();
 61396            services.AddSingleton(typeof(ServiceHostObjectModel<>));
 61397            services.AddSingleton(typeof(TransportCompressionSupportHelper));
 61398            services.AddSingleton(typeof(ServiceDescription<>));
 61399            services.AddSingleton(typeof(ServiceModelOptions));
 613100            AddServicesForFederation(services);
 613101            return services;
 102        }
 103
 104        private static void AddServicesForFederation(IServiceCollection services)
 105        {
 620106            services.AddTransient(provider => new ServiceCredentials(provider));
 613107            services.AddDataProtection();
 613108            services.AddSingleton<ProtectedDataCookieTransform>();
 613109            services.AddTransient<SecurityTokenHandler, SamlSecurityTokenHandler>();
 613110            services.AddTransient<SecurityTokenHandler, Saml2SecurityTokenHandler>();
 613111            services.AddTransient<SecurityTokenHandler, X509SecurityTokenHandler>();
 613112            services.AddTransient<SecurityTokenHandler, EncryptedSecurityTokenHandler>();
 617113            services.AddTransient<SecurityTokenHandler>(provider => new SessionSecurityTokenHandler(SessionSecurityToken
 613114            services.AddTransient<IdentityConfiguration>();
 613115        }
 116    }
 117}