添加属性依赖注入、添加自定义日志扩展
This commit is contained in:
@@ -529,9 +529,9 @@
|
||||
测试控制器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.#ctor(Microsoft.AspNetCore.SignalR.IHubContext{Yi.Framework.WebCore.SignalRHub.MainHub},Microsoft.Extensions.Logging.ILogger{Yi.Framework.Model.Models.UserEntity},Yi.Framework.Interface.IRoleService,Yi.Framework.Interface.IUserService,Microsoft.Extensions.Localization.IStringLocalizer{Yi.Framework.Language.LocalLanguage},Yi.Framework.Core.QuartzInvoker,Yi.Framework.Core.ThumbnailSharpInvoer,Yi.Framework.Core.CacheInvoker)">
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.#ctor(Microsoft.AspNetCore.SignalR.IHubContext{Yi.Framework.WebCore.SignalRHub.MainHub},Microsoft.Extensions.Logging.ILogger{Yi.Framework.ApiMicroservice.Controllers.TestController},Yi.Framework.Interface.IRoleService,Yi.Framework.Interface.IUserService,Microsoft.Extensions.Localization.IStringLocalizer{Yi.Framework.Language.LocalLanguage},Yi.Framework.Core.QuartzInvoker,Yi.Framework.Core.ThumbnailSharpInvoer,Yi.Framework.Core.CacheInvoker)">
|
||||
<summary>
|
||||
依赖注入
|
||||
依赖注入,优雅写法
|
||||
</summary>
|
||||
<param name="hub"></param>
|
||||
<param name="logger"></param>
|
||||
@@ -652,5 +652,17 @@
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.CustomLogTest">
|
||||
<summary>
|
||||
自定义日志
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.TestController.PropertyTest">
|
||||
<summary>
|
||||
属性注入测试
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -37,9 +37,12 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
private IHubContext<MainHub> _hub;
|
||||
private ThumbnailSharpInvoer _thumbnailSharpInvoer;
|
||||
private CacheInvoker _cacheDb;
|
||||
private ILogger<TestController> _logger;
|
||||
[Autowired]
|
||||
public CacheInvoker CacheInvoker { get; set; }
|
||||
//你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来!
|
||||
/// <summary>
|
||||
/// 依赖注入
|
||||
/// 依赖注入,优雅写法
|
||||
/// </summary>
|
||||
/// <param name="hub"></param>
|
||||
/// <param name="logger"></param>
|
||||
@@ -50,22 +53,18 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
/// <param name="thumbnailSharpInvoer"></param>
|
||||
/// <param name="cacheInvoker"></param>
|
||||
public TestController(IHubContext<MainHub> hub,
|
||||
ILogger<UserEntity> logger,
|
||||
ILogger<TestController> logger,
|
||||
IRoleService iRoleService,
|
||||
IUserService iUserService,
|
||||
IStringLocalizer<LocalLanguage> local,
|
||||
QuartzInvoker quartzInvoker,
|
||||
ThumbnailSharpInvoer thumbnailSharpInvoer,
|
||||
CacheInvoker cacheInvoker)
|
||||
{
|
||||
_iUserService = iUserService;
|
||||
_iRoleService = iRoleService;
|
||||
_quartzInvoker = quartzInvoker;
|
||||
_hub = hub;
|
||||
_local = local;
|
||||
_thumbnailSharpInvoer = thumbnailSharpInvoer;
|
||||
_cacheDb = cacheInvoker;
|
||||
}
|
||||
CacheInvoker cacheInvoker) =>
|
||||
|
||||
(_logger,_iUserService, _iRoleService, _quartzInvoker, _hub, _local, _thumbnailSharpInvoer, _cacheDb) =
|
||||
|
||||
(logger, iUserService, iRoleService, quartzInvoker, hub, local, thumbnailSharpInvoer, cacheInvoker);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// swagger跳转
|
||||
@@ -346,5 +345,26 @@ namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
var data = _cacheDb.Get<string>(key);
|
||||
return Result.Success().SetData(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public Result CustomLogTest()
|
||||
{
|
||||
_logger.LogWarning("输出一条日志");
|
||||
return Result.Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 属性注入测试
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public Result PropertyTest()
|
||||
{
|
||||
return Result.Success().SetStatus(CacheInvoker is not null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using Autofac.Extensions.DependencyInjection;
|
||||
using Yi.Framework.WebCore.BuilderExtend;
|
||||
using Yi.Framework.Core;
|
||||
using Yi.Framework.WebCore.MiddlewareExtend;
|
||||
using Yi.Framework.WebCore.Utility;
|
||||
using Autofac;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.Language;
|
||||
@@ -15,6 +14,10 @@ using Yi.Framework.WebCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Yi.Framework.WebCore.DbExtend;
|
||||
using IPTools.Core;
|
||||
using Yi.Framework.WebCore.LogExtend;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Yi.Framework.WebCore.AutoFacExtend;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddCommandLine(args);
|
||||
@@ -31,21 +34,29 @@ builder.Host.ConfigureAppConfiguration((hostBuilderContext, configurationBuilder
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
|
||||
{
|
||||
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD>Module<6C><65><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
containerBuilder.RegisterModule<CustomAutofacModule>();
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ģ<EFBFBD><C4A3>
|
||||
#endregion
|
||||
//containerBuilder.RegisterModule<PropertiesAutowiredModule>();
|
||||
#region
|
||||
//ʹ<><CAB9>AppService<63><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĽ<C5B5><C4BD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>,<2C>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ø<EFBFBD><C3B8>ַ<EFBFBD>ʽ<EFBFBD>Զ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
containerBuilder.AddAutoIocService("Yi.Framework.Repository", "Yi.Framework.Service");
|
||||
});
|
||||
////<2F><><EFBFBD><EFBFBD>ע<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mvcģ<63><C4A3>ת<EFBFBD>Ӹ<EFBFBD>ioc
|
||||
//builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
|
||||
|
||||
builder.Host.ConfigureLogging(loggingBuilder =>
|
||||
{
|
||||
loggingBuilder.AddFilter("System", Microsoft.Extensions.Logging.LogLevel.Warning);
|
||||
loggingBuilder.AddFilter("Microsoft", Microsoft.Extensions.Logging.LogLevel.Warning);
|
||||
loggingBuilder.AddLog4Net("./Config/Log4net.config");
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>־
|
||||
//loggingBuilder.AddCustomLogger();
|
||||
});
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user