コード例 #1
0
        /// <summary>
        /// Optional override to create listeners (like tcp, http) for this service instance.
        /// </summary>
        /// <returns>The collection of listeners.</returns>
        protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            IEnumerable <EndpointResourceDescription> endpoints = Context.CodePackageActivationContext.GetEndpoints()
                                                                  .Where(endpoint => endpoint.Protocol == EndpointProtocol.Http || endpoint.Protocol == EndpointProtocol.Https);

            return(endpoints.Select(endpoint =>
                                    new ServiceInstanceListener(serviceContext =>
                                                                new KestrelCommunicationListener(serviceContext, typeof(IRestApi).Name, (url, listener) =>
            {
                ServiceEventSource.Current.ServiceMessage(serviceContext, $"Starting Kestrel on {url}");

                return new WebHostBuilder()
                .UseKestrel(options =>
                {
                    if (endpoint.Protocol == EndpointProtocol.Http)
                    {
                        options.Listen(IPAddress.Any, endpoint.Port);
                    }
                    else if (endpoint.Protocol == EndpointProtocol.Https)
                    {
                        options.Listen(IPAddress.Any, endpoint.Port, listenOptions => listenOptions.UseHttps(GetCertificate(_ApiCertThumbprint)));
                    }
                })
                .ConfigureServices(
                    services => services
                    .AddTransient(typeof(IMembershipManager), _ => TrackingProxy.ForMicroservice <IMembershipManager>())
                    .AddSingleton(typeof(ILogger), _Logger)
                    .AddSingleton(serviceContext))
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseStartup <Startup>()
                .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
                .UseUrls(url)
                .Build();
            }))));
        }
コード例 #2
0
 static IMembershipManager GetProxy()
 {
     return(TrackingProxy.ForMicroservice <IMembershipManager>());
 }