diff --git a/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs b/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs index 30ec5f6c..fc498ed6 100644 --- a/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs +++ b/src/AgileConfig.Server.Apisite/Controllers/api/AppController.cs @@ -25,17 +25,26 @@ public class AppController : Controller private readonly IPremissionService _premissionService; private readonly IUserService _userService; + private readonly Controllers.AppController _appController; + private readonly Controllers.ConfigController _configController; + public AppController(IAppService appService, IPremissionService premissionService, IUserService userService, IConfigService configService, - ITinyEventBus tinyEventBus) + ITinyEventBus tinyEventBus, + + Controllers.AppController _appController, + Controllers.ConfigController _configController) { _appService = appService; _premissionService = premissionService; _userService = userService; _configService = configService; _tinyEventBus = tinyEventBus; + + this._appController = _appController; + this._configController = _configController; } /// @@ -69,13 +78,7 @@ public async Task>> GetAll() [HttpGet("{id}")] public async Task> GetById(string id) { - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); - var result = (await ctrl.Get(id)) as JsonResult; + var result = (await _appController.Get(id)) as JsonResult; dynamic obj = result.Value; if (obj.success) @@ -121,15 +124,9 @@ public async Task Add([FromBody] ApiAppVM model) }); } - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; + _appController.ControllerContext.HttpContext = HttpContext; - var result = (await ctrl.Add(new AppVM + var result = (await _appController.Add(new AppVM { Id = model.Id, Name = model.Name, @@ -174,16 +171,10 @@ public async Task Edit(string id, [FromBody] ApiAppVM model) }); } - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; + _appController.ControllerContext.HttpContext = HttpContext; model.Id = id; - var result = (await ctrl.Edit(new AppVM + var result = (await _appController.Edit(new AppVM { Id = model.Id, Name = model.Name, @@ -215,15 +206,9 @@ public async Task Edit(string id, [FromBody] ApiAppVM model) [HttpDelete("{id}")] public async Task Delete(string id) { - var ctrl = new Controllers.AppController( - _appService, - _premissionService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; + _appController.ControllerContext.HttpContext = HttpContext; - var result = (await ctrl.Delete(id)) as JsonResult; + var result = (await _appController.Delete(id)) as JsonResult; dynamic obj = result.Value; if (obj.success == true) @@ -249,15 +234,9 @@ public async Task Delete(string id) [HttpPost("publish")] public async Task Publish(string appId, EnvString env) { - var ctrl = new Controllers.ConfigController( - _configService, - _appService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; - - var result = (await ctrl.Publish(new PublishLogVM() + _configController.ControllerContext.HttpContext = HttpContext; + + var result = (await _configController.Publish(new PublishLogVM() { AppId = appId }, env)) as JsonResult; @@ -317,15 +296,9 @@ public async Task>> PublishHistor [HttpPost("rollback")] public async Task Rollback(string historyId, EnvString env) { - var ctrl = new Controllers.ConfigController( - _configService, - _appService, - _userService, - _tinyEventBus - ); - ctrl.ControllerContext.HttpContext = HttpContext; - - var result = (await ctrl.Rollback(historyId, env)) as JsonResult; + _configController.ControllerContext.HttpContext = HttpContext; + + var result = (await _configController.Rollback(historyId, env)) as JsonResult; dynamic obj = result.Value; if (obj.success == true)