ASP.NET Core 2.2 WebApi 系列【三】AutoFac 仓储接口的依赖注入
一、准备工作 通过 程序包管理器控制台 安装AutoFac: Install-Package Autofac.Extensions.DependencyInjection 创建新类库(.NetCore 2.2类库),存放接口跟实现类,命名为NetCoreWebApi.Repository。 创建用户仓储接口 在类库项目上右键->添加->新建文件夹,命名为Interface,存放接口类。在Interface文件夹下面新建类:IUserRepository,属性如下: using System.Collections.Generic; using NetCoreWebApi.Model.Models; namespace NetCoreWebApi.Repository.Interface { /// <summary> /// 用户接口 /// </summary> public interface IUserRepository { /// <summary> /// 添加用户 /// </summary> /// <param name="entity">实体对象</param> int Add(TbUser entity); /// <summary> /// 删除用户 /// </summary> /// <param name="entity">实体对象</param>