예제 #1
0
        /// <summary>
        /// 添加负载均衡器
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configAction"></param>
        /// <returns></returns>
        public static SparkBuilder AddLoadBalancer(this SparkBuilder builder)
        {
            builder.Services.AddSingleton <ILoadBalancerFactory, LoadBalancerFactory>();
            builder.Services.AddSingleton <ILoadBalancerHouse, LoadBalancerHouse>();

            return(builder);
        }
예제 #2
0
        public static SparkBuilder AddLog(this SparkBuilder builder, Action <LogOptions> action)
        {
            var options = new LogOptions();

            action?.Invoke(options);

            foreach (var serviceExtension in options.Extensions)
            {
                serviceExtension.AddServices(builder.Services);
            }

            return(builder);
        }
예제 #3
0
        public static SparkBuilder AddSmartSql(this SparkBuilder builder, params string[] repositoryAssembly)
        {
            builder.Services.AddSmartSql();

            builder.Services.AddRepositoryFactory();
            foreach (var para in repositoryAssembly)
            {
                builder.Services.AddRepositoryFromAssembly((options) =>
                {
                    options.AssemblyString = para;
                });
            }

            return(builder);
        }
예제 #4
0
        /// <summary>
        /// 添加SmartSql支持。从配置中心读取配置
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configurationSection"></param>
        /// <param name="repositoryAssembly">仓库程序集名</param>
        /// <returns></returns>
        public static SparkBuilder AddSmartSql(this SparkBuilder builder, IConfigurationSection configurationSection, params string[] repositoryAssembly)
        {
            builder.Services.Configure <SmartSqlDbConfigOptions>(configurationSection);
            builder.Services.AddSmartSql(sp => new SmartSqlOptions().UseOptions(sp));

            builder.Services.AddRepositoryFactory();
            foreach (var para in repositoryAssembly)
            {
                builder.Services.AddRepositoryFromAssembly((options) =>
                {
                    options.AssemblyString = para;
                });
            }

            return(builder);
        }
예제 #5
0
        /// <summary>
        /// 服务发现
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configAction"></param>
        /// <returns></returns>
        public static SparkBuilder AddServiceDiscovery(this SparkBuilder builder, Action <ServiceDiscoveryOptions> configAction)
        {
            if (configAction == null)
            {
                throw new ArgumentNullException(nameof(configAction));
            }

            var options = new ServiceDiscoveryOptions();

            configAction?.Invoke(options);

            foreach (var serviceExtension in options.Extensions)
            {
                serviceExtension.AddServices(builder.Services);
            }

            return(builder);
        }
예제 #6
0
        /// <summary>
        /// 事件驱动
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="configAction"></param>
        /// <returns></returns>
        public static SparkBuilder AddEventBus(this SparkBuilder builder, Action <EventBusOptions> configAction)
        {
            if (configAction == null)
            {
                throw new ArgumentNullException(nameof(configAction));
            }

            var options = new EventBusOptions();

            configAction?.Invoke(options);

            builder.Services.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();

            foreach (var serviceExtension in options.Extensions)
            {
                serviceExtension.AddServices(builder.Services);
            }

            return(builder);
        }