public void SetupForDI() { _host = AppHostBuilder .CreateDefaultAppBuilder() .Build(); }
public static async Task Main() { await AppHostBuilder.RunAsync(startup => startup.Start()).ConfigureAwait(false); }
public static void BeforeFeature() { //Initialize the MvcTestFramework AppHostBuilder.BuildHost(); }
public static async Task Main(string[] args) => await StartPolicy.ExecuteAsync(() => AppHostBuilder.CreateBuilder(args).RunConsoleAsync());
public static void Test2() { #region prepare config //var config = new RpcLiteConfig //{ // AppId = "10000", // Registry = new RegistryConfigItem("MeropsRegistry", typeof(MeropsRegistryFactory), "http://localhost:12974/api/service/"), // //Monitor = new MonitorConfigItem("ConsoleMonitor", typeof(MeropsMonitorFactory), "http://localhost:6201/api/service/"), // Monitor = new MonitorConfigItem("ConsoleMonitor", typeof(ConsoleMonitorFactory), "http://localhost:6201/api/service/"), // Services = new List<ServiceConfigItem> // { // new ServiceConfigItem("ProductService", typeof(ProductService), "/service/"), // }, // Clients = new List<ClientConfigItem> // { // new ClientConfigItem("ProductService", typeof(IProductService), "/service/"), // } //}; //var appHost = new AppHost(config); //var appHost = new AppHostBuilder() // .UseAppId("10000") // .UseRegistry("MeropsRegistry", typeof(MeropsRegistryFactory), "http://localhost:12974/api/service/") // .UseMonitor("ConsoleMonitor", typeof(ConsoleMonitorFactory), "http://localhost:6201/api/service/") // .UseServices(new ServiceConfigItem("ProductService", typeof(ProductService), "/service/")) // .UseClients(new ClientConfigItem("ProductService", typeof(IProductService), "/service/")) // .Build(); #endregion ////var config1 = new ConfigurationBuilder() //// .AddJsonFile("rpclite.config.json") //// .Build(); ////var config2 = RpcConfigHelper.GetConfig(new CoreConfiguration(config1)); var config = new RpcConfigBuilder() .UseAppId("10000") .UseRegistry <MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") .UseMonitor <ConsoleMonitorFactory>("ConsoleMonitor", "http://localhost:6201/api/service/") .UseInvoker <DefaultInvokerFactory>(null) .UseFilter <UnitTestFilterFactory>() .Build(); var appHost2 = new AppHost(config); var path = "/service/"; var appHost = new AppHostBuilder() .UseAppId("10000") .UseRegistry <MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") .UseMonitor <ConsoleMonitorFactory>("ConsoleMonitor", "http://localhost:6201/api/service/") //.UseServiceMapper<DefaultServiceMapperFactory>("DefaultServiceMapper") .UseService <ProductService>("ProductService", path, null) .UseInvoker <DefaultInvokerFactory>(null) //.UseClient<IProductService>("ProductService", "/service/") .UseFilter <UnitTestFilterFactory>() .Build(); appHost.Initialize(); //appHost.AddFilter(new LogTimeFilter()); //appHost.AddFilter(new LogRequestTimeFilter()); //appHost.AddFilter(new EmptyFilter()); //appHost.AddFilter(new EmptyFilter()); var client = appHost.ClientFactory.GetInstance <IProductService>(); var clientInfo = (IRpcClient <IProductService>)client; clientInfo.Invoker = new MemoryInvoker(appHost, path); clientInfo.Formatter = new XmlFormatter(); clientInfo.Format = "xml"; Console.WriteLine("start test"); try { var id1 = client.Add(new Product { Id = 1, }); Assert.AreEqual(id1, 1); client.Add(null); } catch (Exception ex) { Console.WriteLine(ex); } var exObj = new PlatformNotSupportedException("win31"); try { client.ThrowException(exObj); } catch (Exception ex) { //Assert.AreEqual(ex.GetType(), exObj.GetType()); //Assert.AreEqual(ex.Message, exObj.Message); } var ps = client.GetByIdAsync(1).Result; Assert.AreEqual(ps.Id, 1); var products = client.GetAll(); while (true) { var times = 1000; Console.WriteLine(); Console.Write($"press enter to start {times} test"); Console.ReadLine(); Console.WriteLine("testing..."); var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { //var products2 = client.GetPage(1, 1000); var products22 = client.GetPage(1, 1); //var products3 = client.GetCount(); } stopwatch.Stop(); Console.WriteLine($"Elapsed: {stopwatch.Elapsed.TotalMilliseconds}, {times * 1000 / stopwatch.Elapsed.TotalMilliseconds} tps, {stopwatch.Elapsed.TotalMilliseconds / times}ms/t"); } Console.ReadLine(); }
/// <summary>Specify the startup type to be used by the web host.</summary> /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> to configure.</param> /// <typeparam name="TStartup">The type containing the startup methods for the application.</typeparam> /// <returns>The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</returns> public static AppHostBuilder UseStartup <TStartup>(this AppHostBuilder hostBuilder) where TStartup : class { return(hostBuilder.UseStartup(typeof(TStartup))); }
/// <summary>Specify the startup type to be used by the web host.</summary> /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> to configure.</param> /// <param name="startupType">The <see cref="T:System.Type" /> to be used.</param> /// <returns>The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</returns> public static AppHostBuilder UseStartup(this AppHostBuilder hostBuilder, Type startupType) { hostBuilder.StartupClass = startupType; return(hostBuilder); }
/// <summary>Creates the default builder.</summary> /// <param name="hostBuilder">The host builder to extend.</param> /// <returns>AppHostBuilder instance with defaults of polly retry policies and memory cache applied.</returns> public static AppHostBuilder CreateDefaultBuilder(this AppHostBuilder hostBuilder) { return(hostBuilder.UseDefaultRetryPolicies().AddMemoryCache()); }
public static void Test2() { #region prepare config //var config = new RpcLiteConfig //{ // AppId = "10000", // Registry = new RegistryConfigItem("MeropsRegistry", typeof(MeropsRegistryFactory), "http://localhost:12974/api/service/"), // //Monitor = new MonitorConfigItem("ConsoleMonitor", typeof(MeropsMonitorFactory), "http://localhost:6201/api/service/"), // Monitor = new MonitorConfigItem("ConsoleMonitor", typeof(ConsoleMonitorFactory), "http://localhost:6201/api/service/"), // Services = new List<ServiceConfigItem> // { // new ServiceConfigItem("ProductService", typeof(ProductService), "/service/"), // }, // Clients = new List<ClientConfigItem> // { // new ClientConfigItem("ProductService", typeof(IProductService), "/service/"), // } //}; //var appHost = new AppHost(config); //var appHost = new AppHostBuilder() // .UseAppId("10000") // .UseRegistry("MeropsRegistry", typeof(MeropsRegistryFactory), "http://localhost:12974/api/service/") // .UseMonitor("ConsoleMonitor", typeof(ConsoleMonitorFactory), "http://localhost:6201/api/service/") // .UseServices(new ServiceConfigItem("ProductService", typeof(ProductService), "/service/")) // .UseClients(new ClientConfigItem("ProductService", typeof(IProductService), "/service/")) // .Build(); #endregion ////var config1 = new ConfigurationBuilder() //// .AddJsonFile("rpclite.config.json") //// .Build(); ////var config2 = RpcConfigHelper.GetConfig(new CoreConfiguration(config1)); var config = new RpcConfigBuilder() .UseAppId("10000") .UseRegistry<MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") .UseMonitor<ConsoleMonitorFactory>("ConsoleMonitor", "http://localhost:6201/api/service/") .UseInvoker<DefaultInvokerFactory>(null) .UseFilter<UnitTestFilterFactory>() .Build(); var appHost2 = new AppHost(config); var path = "/service/"; var appHost = new AppHostBuilder() .UseAppId("10000") .UseRegistry<MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") .UseMonitor<ConsoleMonitorFactory>("ConsoleMonitor", "http://localhost:6201/api/service/") //.UseServiceMapper<DefaultServiceMapperFactory>("DefaultServiceMapper") .UseService<ProductService>("ProductService", path, null) .UseInvoker<DefaultInvokerFactory>(null) //.UseClient<IProductService>("ProductService", "/service/") .UseFilter<UnitTestFilterFactory>() .Build(); appHost.Initialize(); //appHost.AddFilter(new LogTimeFilter()); //appHost.AddFilter(new LogRequestTimeFilter()); //appHost.AddFilter(new EmptyFilter()); //appHost.AddFilter(new EmptyFilter()); var client = appHost.ClientFactory.GetInstance<IProductService>(); var clientInfo = (IRpcClient<IProductService>)client; clientInfo.Invoker = new MemoryInvoker(appHost, path); clientInfo.Formatter = new XmlFormatter(); clientInfo.Format = "xml"; Console.WriteLine("start test"); try { var id1 = client.Add(new Product { Id = 1, }); Assert.AreEqual(id1, 1); client.Add(null); } catch (Exception ex) { Console.WriteLine(ex); } var exObj = new PlatformNotSupportedException("win31"); try { client.ThrowException(exObj); } catch (Exception ex) { //Assert.AreEqual(ex.GetType(), exObj.GetType()); //Assert.AreEqual(ex.Message, exObj.Message); } var ps = client.GetByIdAsync(1).Result; Assert.AreEqual(ps.Id, 1); var products = client.GetAll(); while (true) { var times = 1000; Console.WriteLine(); Console.Write($"press enter to start {times} test"); Console.ReadLine(); Console.WriteLine("testing..."); var stopwatch = Stopwatch.StartNew(); for (int i = 0; i < times; i++) { //var products2 = client.GetPage(1, 1000); var products22 = client.GetPage(1, 1); //var products3 = client.GetCount(); } stopwatch.Stop(); Console.WriteLine($"Elapsed: {stopwatch.Elapsed.TotalMilliseconds}, {times * 1000 / stopwatch.Elapsed.TotalMilliseconds} tps, {stopwatch.Elapsed.TotalMilliseconds / times}ms/t"); } Console.ReadLine(); }
private void Test234234() { var appHost = new AppHostBuilder() .UseAppId("10000") .UseRegistry<MeropsRegistryFactory>("MeropsRegistry", "http://localhost:12974/api/service/") //其它配置 .Build(); appHost.Initialize(); }