zoukankan      html  css  js  c++  java
  • 使用Autofac 依赖注入及 swagger 之startup配置

    言语有限,代码如下;

     public IServiceProvider ConfigureServices(IServiceCollection services)
            {
                services
                   .AddCors()
                   .AddMvc();
                JsonConvert.DefaultSettings = () => new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };
    
                //services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
                services.AddSwaggerGen(option =>
                {
                    option.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
                    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                    option.IncludeXmlComments(xmlPath);
                });
               
                var builder = new ContainerBuilder();
                //Register your own services within Autofac
                var selfServices = Assembly.Load("WuMing.Service");
                //Assembly.LoadFile(Path.Combine(HostingEnvironment.WebRootPath, "AUO.SmartCaring.Service.dll"));
                builder.RegisterAssemblyTypes(selfServices).AsImplementedInterfaces();
                var selfRepos_Repo = Assembly.Load("WuMing.Repository");
                //Assembly.LoadFile(Path.Combine(HostingEnvironment.WebRootPath, "AUO.SmartCaring.Repository.dll"));
                builder.RegisterAssemblyTypes(selfRepos_Repo).AsImplementedInterfaces();
                var selfEntity_Repo = Assembly.Load("WuMing.Entity");
                //Assembly.LoadFile(Path.Combine(HostingEnvironment.WebRootPath, "AUO.SmartCaring.Repository.dll"));
                builder.RegisterAssemblyTypes(selfEntity_Repo).AsImplementedInterfaces();
                var selfapi_Repo = Assembly.Load("WuMing.Interface");
                //Assembly.LoadFile(Path.Combine(HostingEnvironment.WebRootPath, "AUO.SmartCaring.Repository.dll"));
                builder.RegisterAssemblyTypes(selfapi_Repo).AsImplementedInterfaces();
                // //Put the framework services into Autofac
                builder.Populate(services);
    
                //Build and return the Autofac collection
                this.ApplicationContainer = builder.Build();
    
                return new AutofacServiceProvider(this.ApplicationContainer);
    
            }
    

      

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                if (env.IsDevelopment())
                {
                    app.UseDeveloperExceptionPage();
                }
                app.UseErrorHandling();
                app.UseSwagger();
    
                // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), 
                // specifying the Swagger JSON endpoint.
                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                });
                app.UseCors(builder =>
               builder
               .AllowAnyOrigin()
               .AllowAnyHeader()
               .AllowAnyMethod()
               );
                app.UseMvc();
            }
    

      

  • 相关阅读:
    H5 通过腾讯地图api定点位置
    常见的css的效果--箭头--三角形--条纹
    vue+element 给表格添加数据,页面不实时刷新的问题
    js 压缩图片
    利用NBI可视化+influxDB时序数据库构建物联网大数据分析平台
    利用NBI大数据可视化工具做RFM模型分析,洞察数据价值,驱动业务增长
    利用Python+NBI大数据可视化工具实现采集到分析整体方案
    类库封装log4net
    浅析Golang的线程模型与调度器
    Python字符串转换为日期时间– strptime
  • 原文地址:https://www.cnblogs.com/yanwuming/p/10463306.html
Copyright © 2011-2022 走看看