✨ feat(新增): 测试依赖注入完成
This commit is contained in:
parent
42a4e76d33
commit
48099c21d1
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GitCommitMessageStorage">
|
||||
<option name="messageStorage">
|
||||
<MessageStorage />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -4,8 +4,7 @@ namespace Bunny.Service.IService.Service;
|
|||
|
||||
public class BaseService : IBaseService
|
||||
{
|
||||
|
||||
public string TestIndex()
|
||||
public string TestIndex()
|
||||
{
|
||||
const string result = "bunny-template 实现自动注入成功";
|
||||
return result;
|
||||
|
|
|
@ -18,6 +18,9 @@ public class BaseConfig
|
|||
{
|
||||
Console.Title = "Bunny Template";
|
||||
|
||||
// 注入服务依赖
|
||||
builder.AddApplicationServices();
|
||||
|
||||
// 配置
|
||||
UseConfiguration(builder);
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
using Bunny.Service.IService;
|
||||
using Bunny.Service.IService.Service;
|
||||
using Bunny.WebApi.Controllers.Base;
|
||||
|
||||
namespace Bunny.WebApi.Config;
|
||||
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
public static void AddApplicationServices(this WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.AddScoped<TemplateController>();
|
||||
builder.Services.AddScoped<IBaseService, BaseService>();
|
||||
}
|
||||
}
|
|
@ -13,7 +13,12 @@ namespace Bunny.WebApi.Controllers.Base;
|
|||
[Route("api/[controller]")]
|
||||
public class TemplateController : ControllerBase
|
||||
{
|
||||
public IBaseService? BaseService { get; set; }
|
||||
private readonly IBaseService _baseService;
|
||||
|
||||
public TemplateController(IBaseService baseService)
|
||||
{
|
||||
_baseService = baseService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 测试走缓存
|
||||
|
@ -26,5 +31,14 @@ public class TemplateController : ControllerBase
|
|||
return Result<string>.Success($"测试走缓存内容:{Response.Headers.CacheControl}");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 测试Service是否注入
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("TestInject")]
|
||||
public Result<string> TestInject()
|
||||
{
|
||||
var testIndex = _baseService.TestIndex();
|
||||
return Result<string>.Success(testIndex);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue