net core 内置方式
接口
public interface ITestService
{
string Test();
}
实现
public class TestService : ITestService
{
public string Test()
{
return "依赖注入";
}
}
在Startup下的ConfigureServices中进行注入
services.AddTransient<ITestService, TestService>();
在控制器中进行使用
private readonly ITestService _TestService;
public HomeController(ITestService TestService)
{
_TestService = TestService;
}
public IActionResult Index()
{
_TestService .Test();
return View();
}
原文转载:http://www.shaoqun.com/a/489896.html
蜜芽宝贝官网:https://www.ikjzd.com/w/1320
卖家精灵:https://www.ikjzd.com/w/532
krazy:https://www.ikjzd.com/w/1801
netcore内置方式接口publicinterfaceITestService{stringTest();}实现publicclassTestService:ITestService{publicstringTest(){return"依赖注入";}}在Startup下的ConfigureServices中进行注入services.AddTransient<ITestS
飞书互动:https://www.ikjzd.com/w/1319
e淘网:https://www.ikjzd.com/w/1698
顺德到乐8小城怎么走?佛山乐8小城自驾车路线?:http://tour.shaoqun.com/a/30422.html
Shopee圣诞大促,如何角逐东南亚?:https://www.ikjzd.com/home/112286
那些外链对网站来说是真正有帮助的:https://www.ikjzd.com/home/132498
没有评论:
发表评论