重写IOC容器绑定逻辑

This commit is contained in:
fengjiayi
2024-09-30 16:36:55 +08:00
parent 55f0e2f70d
commit 85d97f4234
13 changed files with 518 additions and 299 deletions

View File

@@ -31,10 +31,7 @@ namespace Serein.Library.Web
{
private readonly ISereinIOC SereinIOC; // 用于存储路由信息
public Router(ISereinIOC SereinIOC)
{
this.SereinIOC = SereinIOC;
}
/// <summary>
/// 控制器实例对象的类型,每次调用都会重新实例化,[Url - ControllerType]
/// </summary>
@@ -50,9 +47,9 @@ namespace Serein.Library.Web
//private Type PostRequest;
public Router()
public Router(ISereinIOC SereinIOC)
{
this.SereinIOC = SereinIOC;
_routes = new ConcurrentDictionary<string, ConcurrentDictionary<string, MethodInfo>>(); // 初始化路由字典
_controllerTypes = new ConcurrentDictionary<string, Type>(); // 初始化控制器实例对象字典
foreach (API method in Enum.GetValues(typeof(API))) // 遍历 HTTP 枚举类型的所有值

View File

@@ -20,6 +20,8 @@ namespace Serein.Library.Web
public WebServer(IRouter router)
{
this.Router = router;
listener = new HttpListener();
requestLimiter = new RequestLimiter(5, 8);
}
@@ -29,11 +31,6 @@ namespace Serein.Library.Web
private HttpListener listener; // HTTP 监听器
private RequestLimiter requestLimiter; //接口防刷
public WebServer()
{
listener = new HttpListener();
requestLimiter = new RequestLimiter(5, 8);
}
// 启动服务器
public WebServer Start(string prefixe)