public static IApplicationBuilder UseServiceModel(this IApplicationBuilder app, Action <IServiceBuilder> configureServices)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (configureServices == null)
            {
                throw new ArgumentNullException(nameof(configureServices));
            }

            ILoggerFactory loggerFactory  = app.ApplicationServices.GetRequiredService <ILoggerFactory>();
            ILogger        logger         = loggerFactory.CreateLogger(nameof(ServiceModelApplicationBuilderExtensions));
            ServiceBuilder serviceBuilder = app.ApplicationServices.GetRequiredService <ServiceBuilder>();

            configureServices(serviceBuilder);

            IEnumerable <ITransportServiceBuilder> transportServiceBuilders = app.ApplicationServices.GetServices <ITransportServiceBuilder>();
            var transportServiceBuilderSeenTypes = new HashSet <Type>();

            foreach (ITransportServiceBuilder transportServiceBuilder in transportServiceBuilders)
            {
                if (!transportServiceBuilderSeenTypes.Contains(transportServiceBuilder.GetType()))
                {
                    logger.LogDebug($"Calling {transportServiceBuilder.GetType().FullName}.Configure");
                    transportServiceBuilder.Configure(app);
                    transportServiceBuilderSeenTypes.Add(transportServiceBuilder.GetType());
                }
            }

            foreach (IServiceConfiguration serviceConfig in serviceBuilder.ServiceConfigurations)
            {
                foreach (ServiceEndpointConfiguration serviceEndpoint in serviceConfig.Endpoints)
                {
                    ITransportServiceBuilder transportServiceBuilder = serviceEndpoint.Binding.GetProperty <ITransportServiceBuilder>(new BindingParameterCollection());
                    // Check if this transport service builder type has already been used in this app
                    if (transportServiceBuilder != null && !transportServiceBuilderSeenTypes.Contains(transportServiceBuilder.GetType()))
                    {
                        //Console.WriteLine($"Found ITransportServiceBuilder of type {transportServiceBuilder.GetType().FullName}");
                        logger.LogDebug($"Calling {transportServiceBuilder.GetType().FullName}.Configure");
                        transportServiceBuilder.Configure(app);
                        transportServiceBuilderSeenTypes.Add(transportServiceBuilder.GetType());
                    }
                }
            }

            return(app);
        }
Esempio n. 2
0
        public static IApplicationBuilder UseServiceModel(this IApplicationBuilder app, Action <IServiceBuilder> configureServices)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }

            if (configureServices == null)
            {
                throw new ArgumentNullException(nameof(configureServices));
            }

            ServiceBuilder serviceBuilder = app.ApplicationServices.GetRequiredService <ServiceBuilder>();

            configureServices(serviceBuilder);

            return(UseServiceModel(app));
        }
Esempio n. 3
0
 public WrappingIServer(ServiceBuilder serviceBuilder)
 {
     _serviceBuilder = serviceBuilder;
 }
 public ServiceConfiguration(ServiceBuilder serviceBuilder, IServiceProvider services)
 {
     _serviceBuilder = serviceBuilder;
     _services       = services;
 }