Avoiding 'new' in IOC

Hello,

I am learning about dependency injection and one of the things said to avoid is using new in the constructor. How can I avoid doing stuff like this:

    private readonly ILogger<DowntimeClient> _logger;
    private readonly PipeAsync _pipeAsync;
    private readonly Helper _helper;

    private TcpClient _sendingClient;

    private DowntimeClient(ILogger<DowntimeClient> logger, PipeAsync pipeAsync, Helper helper)
    {
        _logger = logger;
        _pipeAsync = pipeAsync;
        _helper = helper;
        _sendingClient = new TcpClient();
    }


where I need _sendingClient throughout multiple methods in the class?

Thanks!
Was this page helpful?