Exemple #1
0
        /// <summary>
        /// The Test
        /// </summary>
        public static void Test()
        {
            //AutofacHelper.Register<ITest1, Test1>();
            AutofacHelper.Register <ITest1, Test1, TestIinterceptor>();
            var it1 = AutofacHelper.Resolve <ITest1>();

            it1.TestMethod();
            Console.WriteLine("--------");
            var ss2 = it1.TestMethod2(1212);

            Console.WriteLine("--------");
            var ss3 = it1.TestMethod3(1212, "fsafasfasfsaf");

            Console.WriteLine("--------");
            var ss4 = it1.TestMethod4(null);

            Console.WriteLine("--------");
            var ss5 = it1.TestMethod4(new TestObj {
                MyProperty = 2132131, MyProperty2 = "afljlfajflsa"
            });

            Console.WriteLine("--------");

            Console.WriteLine(ss2);
            Console.WriteLine(ss3);
            Console.WriteLine(ss4);
            Console.WriteLine(ss5);
        }
Exemple #2
0
        public static IApplicationBuilder UseAllowedOrigins(this IApplicationBuilder app)
        {
            //跨域设置
            var config         = AutofacHelper.Resolve <IConfiguration>();
            var allowedOrigins = config.GetValue <string>("AllowedOrigins") ?? string.Empty;

            return(app.UseCors(builder => builder.WithOrigins(allowedOrigins.Split(',')).AllowAnyMethod().AllowAnyHeader().AllowCredentials()));
        }
Exemple #3
0
 /// <summary>
 /// 注册
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="builder"></param>
 public static void RegisterHttpService <T>(ContainerBuilder builder) where T : class, IHttpApi
 {
     builder.RegisterHttpApi <T>().ConfigureHttpApiConfig(c =>
     {
         var configAttr = typeof(T).GetCustomAttributes(typeof(HttpHostConfigAttribute), false);
         if (configAttr != null && configAttr.Length > 0)
         {
             var hostConfig = configAttr.First() as HttpHostConfigAttribute;
             var config     = AutofacHelper.Resolve <IConfiguration>();
             c.HttpHost     = new Uri(config[hostConfig.Key]);
         }
         c.FormatOptions.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
     });
 }
 public BaseService()
 {
     Repository = AutofacHelper.Resolve <TRepository>();
 }
        /// <summary>
        /// 分库模式
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private static IFreeSql GetFreeSql(string key = null)
        {
            var ib = AutofacHelper.Resolve <IdleBus <IFreeSql> >();

            return(ib.Get($"{key}ConnectionString"));
        }