C#C
C#4y ago
Hercules

❔ How do i register my services in ConsoleApp .net 7

I like to send my httpClient to my logic area (Services for executing some logic) But when i add anything with host it just breaks.

Full code

using WebAPIClient.Extension;

using HttpClient client = new();

var rawSource = await ProcessRepositoriesAsync(client);

static async Task<string> ProcessRepositoriesAsync(HttpClient client)
{
    var source = await client.GetStringAsync(
         "https://www.gutenberg.org/files/45839/45839.txt");
    return source;
}



public class TextService : ITextService
    {
        private readonly HttpClient _httpClient; <--- 
IS PROBABLY NULL Cant try it because it breaks. (top-statement error / same with Main)

        public TextService(HttpClient httpClient)
        {
            _httpClient = httpClient; 
        }

        public string ReadTextAsync(Uri sourcePath)
        {
            // HttpClient client = new();

            //var rawSource = ProcessRepositoriesAsync(client);
            return null;
        }


_httpClient;
IS PROBABLY NULL, I Can't try it because it breaks. (top-statement error / same with Main args in program.cs)
image.png
Was this page helpful?