示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddMemoryCache();

            return(new AutofacServiceProvider(AutofacExt.InitAutofac(services)));
        }
示例#2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddMemoryCache();
            services.AddDbContext <OpenAuthDBContext>(options =>
                                                      options.UseSqlServer(Configuration.GetConnectionString("OpenAuthDBContext")));

            return(new AutofacServiceProvider(AutofacExt.InitAutofac(services)));
        }
示例#3
0
        protected void Application_Start()
        {
            AutofacExt.InitAutofac();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }
示例#4
0
        protected void Application_Start()
        {
            AutofacExt.InitAutofac();

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
        }
示例#5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Version     = "v1",
                    Title       = " OpenAuth.WebApi",
                    Description = "by yubaolee"
                });

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                option.IncludeXmlComments(xmlPath);
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddMemoryCache();
            services.AddCors();
            services.AddDbContext <OpenAuthDBContext>(options =>
                                                      options.UseSqlServer(Configuration.GetConnectionString("OpenAuthDBContext")));

            return(new AutofacServiceProvider(AutofacExt.InitAutofac(services)));
        }
示例#6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Version     = "v1",
                    Title       = " OpenAuth.WebApi",
                    Description = "by yubaolee"
                });

                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                option.IncludeXmlComments(xmlPath);
                option.OperationFilter <GlobalHttpHeaderOperationFilter>(); // 添加httpHeader参数
            });
            services.Configure <AppSetting>(Configuration.GetSection("AppSetting"));
            services.AddMvc().AddControllersAsServices().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddMemoryCache();
            services.AddCors();
            //在startup里面只能通过这种方式获取到appsettings里面的值,不能用IOptions😰
            var dbType = ((ConfigurationSection)Configuration.GetSection("AppSetting:DbType")).Value;

            if (dbType == Define.DBTYPE_SQLSERVER)
            {
                services.AddDbContext <OpenAuthDBContext>(options =>
                                                          options.UseSqlServer(Configuration.GetConnectionString("OpenAuthDBContext")));
            }
            else  //mysql
            {
                services.AddDbContext <OpenAuthDBContext>(options =>
                                                          options.UseMySql(Configuration.GetConnectionString("OpenAuthDBContext")));
            }


            return(new AutofacServiceProvider(AutofacExt.InitAutofac(services)));
        }
示例#7
0
 public void ConfigureContainer(ContainerBuilder builder)
 {
     AutofacExt.InitAutofac(builder);
 }
示例#8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            var identityServer = ((ConfigurationSection)Configuration.GetSection("AppSetting:IdentityServerUrl")).Value;

            if (!string.IsNullOrEmpty(identityServer))
            {
                services.AddAuthorization();

                services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
                .AddJwtBearer(options =>
                {
                    options.Authority            = identityServer;
                    options.RequireHttpsMetadata = false;      // 指定是否为HTTPS
                    options.Audience             = "openauthapi";
                });
            }


            services.AddSwaggerGen(option =>
            {
                option.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
                {
                    Version     = "v1",
                    Title       = " OpenAuth.WebApi",
                    Description = "by yubaolee"
                });

                foreach (var name in Directory.GetFiles(AppContext.BaseDirectory, "*.XML",
                                                        SearchOption.AllDirectories))
                {
                    option.IncludeXmlComments(name);
                }

                option.OperationFilter <GlobalHttpHeaderOperationFilter>(); // 添加httpHeader参数

                if (!string.IsNullOrEmpty(identityServer))
                {
                    //接入identityserver
                    option.AddSecurityDefinition("oauth2", new OAuth2Scheme
                    {
                        Flow             = "implicit",                            // 只需通过浏览器获取令牌(适用于swagger)
                        AuthorizationUrl = $"{identityServer}/connect/authorize", //获取登录授权接口
                        Scopes           = new Dictionary <string, string> {
                            { "openauthapi", "同意openauth.webapi 的访问权限" }//指定客户端请求的api作用域。 如果为空,则客户端无法访问
                        }
                    });
                    option.OperationFilter <AuthResponsesOperationFilter>();
                }
            });
            services.Configure <AppSetting>(Configuration.GetSection("AppSetting"));
            services.AddMvc(config =>
            {
                config.Filters.Add <OpenAuthFilter>();
            }).AddControllersAsServices().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            services.AddMemoryCache();
            services.AddCors();
            //在startup里面只能通过这种方式获取到appsettings里面的值,不能用IOptions😰
            var dbType = ((ConfigurationSection)Configuration.GetSection("AppSetting:DbType")).Value;

            if (dbType == Define.DBTYPE_SQLSERVER)
            {
                services.AddDbContext <OpenAuthDBContext>(options =>
                                                          options.UseSqlServer(Configuration.GetConnectionString("OpenAuthDBContext")));
            }
            else  //mysql
            {
                services.AddDbContext <OpenAuthDBContext>(options =>
                                                          options.UseMySql(Configuration.GetConnectionString("OpenAuthDBContext")));
            }

            services.AddHttpClient();

            services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(Configuration["DataProtection"]));


            return(new AutofacServiceProvider(AutofacExt.InitAutofac(services)));
        }