public void Build_returns_a_service_host_for_service_type(ServiceHostBuilder sut) { var host = sut.Build(typeof(TestService)); Assert.That(host, Is.Not.Null); Assert.That(host.Description.ServiceType, Is.EqualTo(typeof(TestService))); }
private static IJsonRpcServiceHost BuildServiceHost(ISession session, TextWriter logWriter, IJsonRpcContractResolver contractResolver, bool debugMode) { var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider(new DebugLoggerProvider(null)); var builder = new ServiceHostBuilder { ContractResolver = contractResolver, Session = session, Options = JsonRpcServiceHostOptions.ConsistentResponseSequence, LoggerFactory = loggerFactory }; builder.UseCancellationHandling(); builder.Register(typeof(Program).GetTypeInfo().Assembly); if (debugMode) { // Log all the client-to-server calls. builder.Intercept(async(context, next) => { lock (logWriter) logWriter.WriteLine("> {0}", context.Request); await next(); lock (logWriter) logWriter.WriteLine("< {0}", context.Response); }); } return(builder.Build()); }
static async Task Main(string[] args) { var hostBuilder = new ServiceHostBuilder(); hostBuilder.Build((hostBuilderConext, serviceCollection) => { serviceCollection.AddScoped <ITask, PaymentServiceTask>(); }); await hostBuilder.StartAsyncAndWait(); }
static void Main(string[] args) { var builder = new ServiceHostBuilder(); builder.ConfigureOptions <ClusterMembershipServiceOptions>(); builder.ConfigureOptions <GatewayMembershipServiceOptions>(); builder.AddSystemTarget <IClusterMembershipService, ClusterMembershipService>(); builder.AddSystemTarget <IGatewayMembershipService, GatewayMembershipService>(); builder.AddService <IDataService, DataService>(); serviceHost = builder.Build(); serviceHost.Start(); Console.WriteLine("started..."); Console.ReadLine(); serviceHost.Stop(); }
static void Main(string[] args) { var loggerFactory = new LoggerFactory(); loggerFactory.AddProvider <ConsoleLoggerProvider>(); Logger.LoggerFactory = loggerFactory; var builder = new ServiceHostBuilder(); builder.ConfigureOptions <ClusterMembershipServiceOptions>(p => { p.InsideAddress = new SlioAddress("0.0.0.0", 64000); p.Backlog = 10; p.MaxConnections = 100; }); builder.ConfigureOptions <GatewayMembershipServiceOptions>(p => { p.InsideAddress = new SlioAddress("0.0.0.0", 64001); p.Backlog = 10; p.MaxConnections = 100; p.Cluster = new SlioAddress("0.0.0.0", 64000); }); builder.AddSystemTarget <IClusterMembershipService, ClusterMembershipService>(); builder.AddSystemTarget <IGatewayMembershipService, GatewayMembershipService>(); builder.AddService <ISayService, SayService>(metadata: new ServiceMetadata() { ID = 45 }); builder.AddService <IHelloService, HelloService>(); serviceHost = builder.Build(); serviceHost.Lifecycle.WithStarted(nameof(Program), (token) => { var serviceFactory = serviceHost.ServiceFactory; var helloService = serviceFactory.GetSingleService <ISayService>(); var metadata = helloService.Metadata; var result = helloService.Say("cxx"); }); serviceHost.Start(); Console.WriteLine("started..."); Console.ReadLine(); }
public static async Task Main(string[] args) { var hostBuilder = new ServiceHostBuilder(); hostBuilder.Build((hostBuilderConext, serviceCollection) => { serviceCollection.AddScoped <ITask, AccountServiceTask>(); }); await hostBuilder.StartAsync(); //Just to Start the Flow var serviceCoordinator = hostBuilder.host.Services.GetRequiredService <IServiceCoordinator>(); await serviceCoordinator.Raise <CartUpdatedEvent>(new ServiceParams { Message = "Startup", Count = 0 }); Console.WriteLine("Account Service started..."); await hostBuilder.WaitForShutdownAsync(); }
static async Task Main(string[] args) { var hostBuilder = new ServiceHostBuilder(); hostBuilder.Build((hostBuilderConext, serviceCollection) => { }); await hostBuilder.StartAsync(); //Just to Start the Flow var serviceCoordinator = hostBuilder.host.Services.GetRequiredService <IServiceCoordinator>(); Console.WriteLine("External Service started..."); for (int i = 0; i < 10; i++) { await serviceCoordinator.Raise <OrderCreatedEvent>(new ServiceParams { Message = "Startup", Count = 0 }); } await hostBuilder.StartAsyncAndWait(); }
public void Build_adds_base_addresses(ServiceHostBuilder sut, Uri baseAddress) { var host = sut.Build(typeof(TestService), baseAddress); Assert.That(host.BaseAddresses, Contains.Item(baseAddress)); }
public void Build_adds_support_for_dependency_injection(ServiceHostBuilder sut) { var host = sut.Build(typeof(TestService)); Assert.That(host.Description.Behaviors, Has.Exactly(1).InstanceOf <DependencyInjectionServiceBehavior>()); }
static void Main(string[] args) { var pipeName = Guid.NewGuid().ToString("N"); var addresses = Dns.GetHostAddresses(Dns.GetHostName()); var address = addresses.First(p => p.AddressFamily == AddressFamily.InterNetwork); var endpoint = new IPEndPoint(address, 65530); var serviceHostBuilder = new ServiceHostBuilder() //.ConfigureSingleOption<ServiceOption>(option => //{ // option.Credentials = new ServerCredentials(pipeName); //}) .AddSingleService <LoginService>() .AddSingleService <CryptoTransformService>() .ConfigureSingleBinding <BasicPipeBinding>() .ConfigureSingleOption <BasicPipeBindingOptions>(option => { option.PipeName = pipeName; }); //.ConfigureSingleBinding<BasicTcpBinding>() //.ConfigureSingleOption<BasicTcpBindingOption>(option => //{ // option.EndPoint = endpoint; // option.Backlog = 4; // option.MaxAcceptOps = 10; // option.MaxConnections = 100; //}); //.ConfigureSingleBinding<BasicHttpBinding>() //.ConfigureSingleOption<BasicHttpBindingOption>(option => //{ // option.Url = "http://localhost/"; //}); var serviceHost = serviceHostBuilder.Build(); serviceHost.Start(); Console.WriteLine("started..."); var clientBuilder = new ClientBuilder() //.ConfigureSingleOption<ClientOption>(option => //{ // option.Credentials = new ClientCredential("sss", pipeName); //}) .ConfigureSingleBinding <BasicPipeBinding>() .ConfigureSingleOption <BasicPipeBindingOptions>(option => { option.ServiceName = "."; option.PipeName = pipeName; }); //.ConfigureSingleBinding<BasicTcpBinding>() //.ConfigureSingleOption<BasicTcpBindingOption>(option => //{ // option.EndPoint = endpoint; //}); //.ConfigureSingleBinding<BasicHttpBinding>() //.ConfigureSingleOption<BasicHttpBindingOption>(option => //{ // option.Url = "http://localhost/"; //}); var client = clientBuilder.Build(); var loginService = client.GetService <ILoginService>(); var cryptoTransformService = client.GetService <ICryptoTransformService>(); var result = loginService.Login("zzz", "xxx"); var loginToken = loginService.GetToken("zzz"); var bytes = cryptoTransformService.Encrypt(loginToken, "hello world!"); var text = cryptoTransformService.Decrypt(loginToken, bytes); var stopwatch = System.Diagnostics.Stopwatch.StartNew(); var times = 10000; for (int i = 0; i < times; i++) { loginService.Hello(); } stopwatch.Stop(); var value = times / stopwatch.Elapsed.TotalSeconds; var duration = stopwatch.Elapsed; Console.ReadLine(); }