示例#1
0
 /// <summary>
 /// 得到实现类唯一标示
 /// </summary>
 /// <returns></returns>
 public string GetIdentify()
 {
     return(AssemblyCommon.GetReflectedInfo().Namespace);
 }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddLogstashLogger();
            services.AddLogger();
            services.AddCors();
            services.AddSession();
            services.AddSignalR();
            services.AddSingleton <IUserIdProvider, CustomUserIdProvider>();

            // services.AddMvc(options => options.Filters.Add(typeof(CustomExceptionFilterAttribute)))
            //   .AddJsonOptions(options => options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss");
            services.AddTransient <SampleInterface, SampleClass>();
            services.AddServiceEventBusExpression();  //事件总线
            services.AddSingleton <IEventHandler <MyTestEventData>, MyTestEventHandler>();
            services.AddSingleton <IEventHandler <MyTestEventData>, MyTestTwoEventHandler>();
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(LogFilter));
                options.Filters.Add(typeof(ModelValidateFilter));
                options.Filters.Add(typeof(CustomExceptionFilterAttribute));
                options.OutputFormatters.Add(new ProtobufFormatter());
            }).SetCompatibilityVersion(CompatibilityVersion.Version_2_0);



            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v2", new Info
                {
                    Version     = "v2",
                    Title       = "OneTest接口文档",
                    Description = "RESTful API for OneTest"
                });
                var basePath = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationBasePath;
                var xmlPath  = Path.Combine(basePath, "GaoJD.Club.OneTest.xml");
                c.IncludeXmlComments(xmlPath);
                c.OperationFilter <HttpHeaderOperation>(); // 添加httpHeader参数
            });
            services.AddHttpContextAccessor();

            services.AddHttpClient();

            //services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            //   .AddCookie(o => o.LoginPath = new PathString("/login"));


            services.AddResponseCompression();

            services.Configure <GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Fastest;
            });


            // services.AddTransient<SampleInterface, SampleClass>();
            // services.AddDynamicProxy();

            services.AddScoped(typeof(ILogicBase <>), typeof(LogicBase <>));
            services.AddScoped(typeof(IRepositoryBase <>), typeof(RepositoryBase <>));
            var builder = new ContainerBuilder();//实例化 AutoFac  容器

            builder.Populate(services);


            builder.RegisterType <AppConfigurtaionServices>().SingleInstance();
            //注入Redis
            builder.RegisterType <RedisClient>().As <IRedisClient>().SingleInstance();
            builder.RegisterType(typeof(OpenConfiguration));
            Assembly[] asmLopgic = AssemblyCommon.GetAllAssembly("*.Logic.dll").ToArray();
            builder.RegisterAssemblyTypes(asmLopgic)
            .Where(t => t.Name.EndsWith("Logic"))
            .AsImplementedInterfaces().AsSelf();

            //注册仓储
            Assembly[] asmRepository = AssemblyCommon.GetAllAssembly("*.Repository.dll").ToArray();
            builder.RegisterAssemblyTypes(asmRepository)
            .Where(t => t.Name.EndsWith("Repository"))
            .AsImplementedInterfaces().AsSelf();
            //  builder.RegisterGeneric(typeof(LogicBase<>)).As(typeof(ILogicBase<>)).InstancePerDependency();
            //  builder.RegisterGeneric(typeof(RepositoryBase<>)).As(typeof(IRepositoryBase<>)).InstancePerDependency();

            ApplicationContainer = builder.Build();
            return(new AutofacServiceProvider(ApplicationContainer));//第三方IOC接管 core内置DI容器
        }