コード例 #1
0
        public void Run(Action <IServiceCollection> configureServicesAction = null, Action <WebHostBuilderContext, IApplicationBuilder> configureAction = null, string settingName = "JimuAppClientSettings")
        {
            var hostBuilder = Host.CreateDefaultBuilder();

            _hostBuilderAction?.Invoke(hostBuilder);

            var clientBuilder = new ApplicationClientBuilder(new ContainerBuilder(), settingName);

            _clientBuilderAction?.Invoke(clientBuilder);

            var path       = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var executeAss = Assembly.GetCallingAssembly();

            hostBuilder.UseWebHostJimu(clientBuilder.Build()
                                       , configureServicesAction
                                       , configureAction
                                       , mvcBuilder =>
            {
                mvcBuilder.AddApplicationPart(executeAss);
                var viewDll = Path.Combine(path, executeAss.GetName().Name + ".Views.dll");
                if (File.Exists(viewDll))
                {
                    mvcBuilder.AddApplicationPart(Assembly.LoadFrom(viewDll));
                }
            },
                                       _webHostBuilderAction
                                       );
            hostBuilder.Build().Run();
        }
コード例 #2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     _builder = new ApplicationClientBuilder(new ContainerBuilder());
     //_builder.UseJimu()
     _jimuApp = _builder.Build();
     services.AddControllers();
     services.AddJimu(_jimuApp);
     //services.AddJimu();
 }
コード例 #3
0
 public static void BuildHostModule(this ApplicationClientBuilder appBuilder, IHostBuilder hostBuilder = null)
 {
     if (hostBuilder != null)
     {
         var type        = typeof(ClientGeneralModuleBase);
         var hostModules = AppDomain.CurrentDomain.GetAssemblies()
                           .SelectMany(x => x.GetTypes())
                           .Where(x => x.IsClass && type.IsAssignableFrom(x) && !x.IsAbstract)
                           .Select(x => Activator.CreateInstance(x, appBuilder.JimuAppSettings) as ClientGeneralModuleBase)
                           .OrderBy(x => x.Priority);
         foreach (var module in hostModules)
         {
             module.DoHostBuild(hostBuilder);
         }
         hostBuilder.ConfigureServices(sc => appBuilder.AddBeforeBuilder((cb) => cb.Populate(sc)));
     }
 }
コード例 #4
0
        public static ApplicationClientBuilder UseToken(
            this ApplicationClientBuilder serviceHostBuilder, Func <string> getToken)
        {
            serviceHostBuilder.AddComponent(containerBuilder =>
            {
                containerBuilder.RegisterType <ServiceTokenGetter>().As <IServiceTokenGetter>().SingleInstance();
            });

            serviceHostBuilder.AddInitializer(componentRegister =>
            {
                var tokenGetter      = componentRegister.Resolve <IServiceTokenGetter>();
                tokenGetter.GetToken = getToken;


                var logger = componentRegister.Resolve <ILogger>();
                logger.Info($"[config]get token has been set");
            });

            return(serviceHostBuilder);
        }
コード例 #5
0
        static void InitProxyService()
        {
            var containerBuilder = new ContainerBuilder();
            var host             = new Jimu.Client.ApplicationClientBuilder(containerBuilder)
                                   //.UseLog4netLogger(new LogOptions { EnableConsoleLog = true })
                                   //.UsePollingAddressSelector()
                                   //.UseConsulForDiscovery(new Jimu.Client.Discovery.ConsulIntegration.ConsulOptions("127.0.0.1", 8500, "JimuService-"))
                                   //.UseDotNettyForTransfer()
                                   //.UseHttpForTransfer()
                                   //.UseServiceProxy(new Jimu.Client.Proxy.ServiceProxyOptions(new[] { "IServices" }))
                                   .Build()
            ;

            host.Run();
            var proxy = host.Container.Resolve <IServiceProxy>();

            _echoService = proxy.GetService <IEchoService>();
            Task.Run(() =>
            {
                Thread.Sleep(5000);
                var ret = _echoService.GetEcho("哈哈");
                Console.WriteLine("==== echo " + ret);
            });
        }