IOC容器添加构造函数注入(DLL类中使用AutoRegisterAttribute特性标注的类,会在流程启动时自动注册),提高可读性。

This commit is contained in:
fengjiayi
2024-09-30 02:45:49 +08:00
parent 7a310ff1df
commit ccf539b90f
23 changed files with 615 additions and 280 deletions

View File

@@ -29,6 +29,12 @@ namespace Serein.Library.Web
/// </summary>
public class Router : IRouter
{
private readonly ISereinIOC SereinIOC; // 用于存储路由信息
public Router(ISereinIOC SereinIOC)
{
this.SereinIOC = SereinIOC;
}
/// <summary>
/// 控制器实例对象的类型,每次调用都会重新实例化,[Url - ControllerType]
/// </summary>
@@ -39,8 +45,7 @@ namespace Serein.Library.Web
/// </summary>
private readonly ConcurrentDictionary<string, ConcurrentDictionary<string, MethodInfo>> _routes;
[AutoInjection]
public ISereinIOC SereinIOC { get; set; } // 用于存储路由信息
// private readonly ILoggerService loggerService; // 用于存储路由信息
//private Type PostRequest;

View File

@@ -13,13 +13,18 @@ namespace Serein.Library.Web
/// <summary>
/// HTTP接口监听类
/// </summary>
[AutoRegister]
public class WebServer
{
[AutoInjection]
public IRouter Router { get; set; } // 路由器
private readonly IRouter Router;// 路由器
public WebServer(IRouter router)
{
this.Router = router;
}
[AutoInjection]
public NodeRunCts nodeRunCts { get; set; }
//[AutoInjection]
//public NodeRunCts nodeRunCts { get; set; }
private HttpListener listener; // HTTP 监听器
private RequestLimiter requestLimiter; //接口防刷