Hi. How I should use AppService Class defined in Application Layer in MVC Web Project? Exactly my problem is constrictor of AppService that take a IRepository as parameter.
[AbpAuthorize]
public class MenuGroupAppService: WebUIAppServiceBase, IMenuGroupAppService
{
private readonly IRepository<MenuGroup> _menuGroupRepository;
public MenuGroupAppService(IRepository<MenuGroup> menuGroupRepository)
{
_menuGroupRepository = menuGroupRepository;
}
public IQueryable<MenuGroup> GetAllCreateMenuGroupInputs()
{
return _menuGroupRepository.GetAll();
}
public async Task<ListResultOutput<MenuGroupListDto>> GetList(GetMenuGroupListInput input)
{
var menuGroups = await _menuGroupRepository
.GetAll()
.OrderByDescending(e => e.MenuOrderNO).ToListAsync();
return new ListResultOutput<MenuGroupListDto>(menuGroups.MapTo<List<MenuGroupListDto>>());
}
}
and in controller how I should use MenuGroupAppService class for get list of menu groups ?
[HttpGet]
public List<GetMenuGroupListInput> GetAllMenuGroups()
{
return new MenuGroupAppService(WHAT I SHOULD PASS HERE?).
GetList(new GetMenuGroupListInput {JustEspMenus = true});
}
Thakyou.
3 Answer(s)
-
0
Don't create instances of services yourself. Use dependency injection always. So, you can inject app service into your controller. Please see dependency injection document, otherwise you will have more questions without understand DI well: <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Dependency-Injection">http://www.aspnetboilerplate.com/Pages/ ... -Injection</a>
-
0
Hi. Thank you . my problem solved by using DI and your default awesome classes for DI framework. But this is another problem , running this block of code :
var menuGroups = await _menuGroupRepository .GetAll() .OrderByDescending(e => e.MenuOrderNO).ToListAsync();
is very slow and sometimes project fails. Can you help me about this.
-
0
It queries to database and seems not related to the framework. You should investigate the problem (you my use Sql Server profiler for example).