大部分情况下只注入SqlSugar对象已经够开发了,为了让大家使用更加方便,也提供了业务类的注入
其中NETAPI是WebApi生成DLL的名字,也就是程序集名称,默认情况下API项目名称等于程序集名称
public void ConfigureServices(IServiceCollection services) { //注入控制器 services.AddIoc(this,"NETAPI", it => it.Name.Contains("Controller")); }
条件: API项目必须引用BizTest类库
注入对象:
项目名称为 BizTest ,并且带有Test的所有类注入有效
services.AddIoc(this, "NETAPI", it => it.Name.Contains("Controller")); //注入业务类 services.AddIoc(this,"BizTest", it => it.Name.Contains("Test"));
[ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { Test1 class1; public WeatherForecastController(Test1 c1 ) { this.class1 = c1; } [HttpGet] public DateTime Get() { var datetime = class1.GetDate(); return datetime; } }
2016 © donet5.comApache Licence 2.0