使用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();
}
使用Autofac 依赖注入及 swagger 之startup配置的更多相关文章
- ASP.NETCore使用AutoFac依赖注入
原文:ASP.NETCore使用AutoFac依赖注入 实现代码 1.新建接口类:IRepository.cs,规范各个操作类的都有那些方法,方便管理. using System; using Sys ...
- ADO.NET .net core2.0添加json文件并转化成类注入控制器使用 简单了解 iTextSharp实现HTML to PDF ASP.NET MVC 中 Autofac依赖注入DI 控制反转IOC 了解一下 C# AutoMapper 了解一下
ADO.NET 一.ADO.NET概要 ADO.NET是.NET框架中的重要组件,主要用于完成C#应用程序访问数据库 二.ADO.NET的组成 ①System.Data → DataTable, ...
- Autofac 依赖注入小知识
Autofac 依赖注入小知识 控制反转/依赖注入 IOC/DI 依赖接口而不依赖于实现,是面向对象的六大设计原则(SOLID)之一.即依赖倒置原则(Dependence Inversion Prin ...
- 从零开始,搭建博客系统MVC5+EF6搭建框架(2),测试添加数据、集成Autofac依赖注入
一.测试仓储层.业务层是否能实现对数据库表的操作 1.创建IsysUserInfoRepository接口来继承IBaseRepository父接口 namespace Wchl.WMBlog.IRe ...
- 【干货】利用MVC5+EF6搭建博客系统(二)测试添加数据、集成Autofac依赖注入
PS:如果图片模糊,鼠标右击复制图片网址,然后在浏览器中打开即可. 一.测试仓储层.业务层是否能实现对数据库表的操作 1.在52MVCBlog.IRepository程序集下创建IsysUserInf ...
- asp.net mvc4 简单使用Autofac依赖注入小结
1,首先使用 NuGet下载适当的Autofac版本 文件一,Autofac.3.5.2 文件二,Autofac.Mvc4.3.1.0 1,接口类 public interface IReposito ...
- Autofac依赖注入
简介 Autofac 是一款超赞的.NET IoC 容器 . 它管理类之间的依赖关系, 从而使 应用在规模及复杂性增长的情况下依然可以轻易地修改 .它的实现方式是将常规的.net类当做 组件 处理. ...
- Autofac依赖注入框架
最近使用Autofac框架做项目的依赖注入,感觉挺好用的. 没有深入研究,只是拿来用用,具体可以去官网看看:https://autofac.org/. 这里只是贴一下最近项目的配置: public p ...
- Autofac依赖注入容器
依赖注入容器-- Autofac https://github.com/danielpalme/IocPerformance Unity 更新频率高,微软的项目Grace 综合性能更高 目录: 一.简 ...
随机推荐
- js 实现二叉排序树
二叉排序树或者是一棵空树,或者是具有下列性质的二叉树: (1)若左子树不空,则左子树上所有结点的值均小于或等于它的根结点的值: (2)若右子树不空,则右子树上所有结点的值均大于或等于它的根结点的值: ...
- Cadence——每次启动软件弹出找不到license文件的提示窗口
1. 摘要 按照Cadence16.60,每次启动该软件,总弹出提示窗口,内如大致为:Orcad Capture license was not found.... 2. 解决方法 参考此链接:htt ...
- 51nod 1353 树
树背包 设f[i][j]表示第i个点,和子节点组成的联通块大小为j,其他都可行的方案 j=0表示可行的总方案 #include<cstdio> #include<iostream&g ...
- P3567 [POI2014]KUR-Couriers 主席树
这个题比一般主席树还要简单,但是用来练习主席树再好不过了,在这里我再放一下主席树板子. 代码: #include<iostream> #include<cstdio> #inc ...
- 懒人学习automake, Makefile.am,configure.ac
已经存在Makefile.am,如何生成Makefile? 步骤: [root@localhost hello]# autoscan .///在当前文件夹中搜索 [root@localhost hel ...
- PCB 挺有意思的基数排序----C#代码实现
今天在头条看一个很有意思的排序算法[基数排序],以前所学习的排序算法都是基于数值对比的方式排序的,而这个算法挺有意思的非常独特.但从网上看到的例子通常是对个位,十位处理,并转为对应的桶索引的方式实现, ...
- 【WIP】客户端JavaScript DOM
创建: 2017/10/12 初步完成: 2017/10/15 更新: 2017/10/14 标题加上[WIP],继续完成 [TODO] 补充暂略的, 搜[略] DOM树 概要 基本 ...
- 329 Longest Increasing Path in a Matrix 矩阵中的最长递增路径
Given an integer matrix, find the length of the longest increasing path.From each cell, you can eith ...
- STMP服务器发送邮件,本地可以发送但是服务器一直发送不成功;
在官网上查看到信息 考虑到部分云服务商封禁了其内网对外 25 端口的访问, xxxxx 端口号: 2525 xxxxx 端口号: 587 然后,我换了一下端口号就行了,浪费了我三个小时时间,贼尴尬:
- CxImage实现9PNG
CxImage* ScaleImageBy9PNG(CxImage *pRawImage, int nDstWidth,int nDstHeight) { if(NULL == pRawImage) ...