Example #1
0
 private void Invoke(object instance, IMicroServiceBuilder builder)
 {
     var serviceProvider = builder.ApplicationServices;
     var parameterInfos = MethodInfo.GetParameters();
     var parameters = new object[parameterInfos.Length];
     for (var index = 0; index != parameterInfos.Length; ++index)
     {
         var parameterInfo = parameterInfos[index];
         if (parameterInfo.ParameterType == typeof(IMicroServiceBuilder))
         {
             parameters[index] = builder;
         }
         else
         {
             try
             {
                 parameters[index] = serviceProvider.GetRequiredService(parameterInfo.ParameterType);
             }
             catch (Exception)
             {
                 throw new Exception(string.Format(
                     "Could not resolve a service of type '{0}' for the parameter '{1}' of method '{2}' on type '{3}'.",
                     parameterInfo.ParameterType.FullName,
                     parameterInfo.Name,
                     MethodInfo.Name,
                     MethodInfo.DeclaringType.FullName));
             }
         }
     }
     MethodInfo.Invoke(instance, parameters);
 }
Example #2
0
        public static IMicroServiceBuilder RegisterService <T>(this IMicroServiceBuilder builder) where T : class, IGrpcService
        {
            builder.Services.AddScoped <T>();
            builder.Services.AddSingleton <IGrpcService, T>();

            return(builder);
        }
Example #3
0
        public static IMicroServiceBuilder AddAppMetrics(this IMicroServiceBuilder builder, IConfigurationSection section)
        {
            builder.Services.AddMetrics(metricsBuilder =>
            {
                var influxDbSection = section.GetSection("InfluxDbReporter");

                metricsBuilder.Configuration.ReadFrom(section.GetSection("Options"));
                metricsBuilder.Report.ToInfluxDb(options =>
                {
                    options.InfluxDb.BaseUri  = new Uri(influxDbSection.GetValue <string>("BaseUri"));
                    options.InfluxDb.Database = influxDbSection.GetValue <string>("Database");
                    options.InfluxDb.UserName = influxDbSection.GetValue <string>("UserName");
                    options.InfluxDb.Password = influxDbSection.GetValue <string>("Password");
                    options.FlushInterval     = TimeSpan.FromSeconds(5);
                });
            });
            return(builder);
        }
Example #4
0
 public static IMicroServiceBuilder AddServiceStackRedis(this IMicroServiceBuilder builder, string[] masters, string[] slaves, int maxWritePoolSize, int maxReadPoolSize, bool autoStart, int defaultDb)
 {
     builder.Services.AddSingleton <IRedisRepository>(p => new ServiceStackRedisRespository(masters, slaves, maxReadPoolSize, maxWritePoolSize, autoStart, defaultDb));
     return(builder);
 }
Example #5
0
 public static IMicroServiceBuilder AddStackExchangeRedis(this IMicroServiceBuilder builder, string redisConnectionString)
 {
     builder.Services.AddSingleton <IRedisRepository>(p => new StackExchangeRedisRespository(redisConnectionString));
     return(builder);
 }
Example #6
0
 public static IMicroServiceBuilder AddMysql(this IMicroServiceBuilder builder, string dbConnectionString)
 {
     builder.Services.AddDbContextPool <ApplicationDbContext>(options => options.UseMySQL(dbConnectionString));
     builder.Services.AddUnitOfWork <ApplicationDbContext>();
     return(builder);
 }