In the .NET Core I know that we have async
and await
to request async .
So far so good, but many frameworks on the market are creating methods with the MetodoAsync()
signature and have the method without being async Metodo()
.
We can use async
so
[HttpGet]
public async Task<JsonResult> Get()
{
return await Task.Run(() => Json(_fachadaGrupo.BuscarTodos()));
}
Remembering that in internal methods _fachadaGrupo.BuscarTodos()
. the async method does not exist, it uses a connection to the nHibernate database, and it does not have the Async()
method at the moment. So I wanted to know if this still has the same efficiency and the same logic happens internally in which thread is freed up for new requests . Or it is the same as not having.
// facade
public IEnumerable<GrupoDto> BuscarTodos()
{
return _buscarTodos.Buscar();
}
// Serviço
public IEnumerable<GrupoDto> Buscar()
{
IRepositorioGrupo repositorioGrupo = new RepositorioGrupo(_nHibernateHelper);
return repositorioGrupo.Lista(_usuario);
}
// repositorio
public IEnumerable<GrupoDto> Lista(Usuario usuario)
{
Usuario usuarioAlias = null;
Grupo grupo = null;
GrupoDto grupoDto = null;
return Sessao.QueryOver(() => grupo).JoinAlias(() => grupo.Usuario, () => usuarioAlias)
.SelectList(list => list.Select(() => grupo.Id).WithAlias(() => grupoDto.Id)
.Select(() => grupo.Descricao).WithAlias(() => grupoDto.Descricao))
.TransformUsing(Transformers.AliasToBean<GrupoDto>())
.Where(g => g.Usuario == usuario).OrderBy(g => g.Id).Desc.List<GrupoDto>();
}