Beispiel #1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // MVC
            services.AddMvc(
                options => options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute())
                );

            IdentityRegistrar.Register(services);
            AuthConfigurer.Configure(services, _appConfiguration);

            services.AddScoped <IWebResourceManager, WebResourceManager>();

            services.AddSignalR();

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info
                {
                    Title       = "AbpZeroTemplate API",
                    Description = "提供移动端或其它系统集成到自定义平台需要的api接口。",
                    Version     = "v1"
                });
                options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyProject.Application.xml"));
                options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyProject.Web.Core.xml"));
                options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyProject.Web.Mvc.xml"));
                options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "MyProject.Common.xml"));
                // options.DocInclusionPredicate((docName, description) => true);
                options.TagActionsBy(api =>
                {
                    MethodInfo methodInfo;
                    api.TryGetMethodInfo(out methodInfo);
                    var attr = methodInfo.GetCustomAttributes <ApiDocumentAttribute>().FirstOrDefault() ??
                               methodInfo.DeclaringType.GetCustomAttributes <ApiDocumentAttribute>().FirstOrDefault();

                    return(new List <string> {
                        attr.GroupName ?? api.GroupName
                    });
                });
                options.OrderActionsBy((apiDesc) => $"{apiDesc.ActionDescriptor.RouteValues["controller"]}_{apiDesc.HttpMethod}");
                options.DescribeAllEnumsAsStrings();
                options.DocInclusionPredicate((docName, description) =>
                {
                    MethodInfo methodInfo;
                    description.TryGetMethodInfo(out methodInfo);
                    var attrs = methodInfo.GetCustomAttributes <ApiDocumentAttribute>();
                    if (attrs.Any())
                    {
                        return(true);
                    }
                    else
                    {
                        attrs = methodInfo.DeclaringType.GetCustomAttributes <ApiDocumentAttribute>();
                        return(attrs.Any());
                    }
                });
                options.CustomSchemaIds(x => x.FullName);
                options.OperationFilter <SecurityRequirementsOperationFilter>();
            });

            // Configure Abp and Dependency Injection
            return(services.AddAbp <MyProjectWebMvcModule>(
                       // Configure Log4Net logging
                       options => options.IocManager.IocContainer.AddFacility <LoggingFacility>(
                           f => f.UseAbpLog4Net().WithConfig("log4net.config")
                           )
                       ));
        }