fix(host): pass HttpClient to EspoCrmClient ctor + dispose on shutdown
The composition root was calling EspoCrmClient(baseUrl, user, key, logger) which doesn't match the actual ctor signature EspoCrmClient(HttpClient, string, string, string, ILogger). One missing HttpClient argument = one compile error blocking the host build. - AddInHost now owns a single HttpClient (Timeout=30s), passed to EspoCrmClient on init, disposed alongside the retry processor and Serilog on shutdown. - baseUrl.ToString() satisfies the string parameter; the Uri.TryCreate upstream still validates the URL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -36,6 +37,7 @@ namespace OutlookAddin.Services
|
||||
|
||||
private readonly Outlook.Application _outlookApp;
|
||||
private RetryQueueProcessor? _retryProcessor;
|
||||
private HttpClient? _httpClient;
|
||||
|
||||
public AddInHost(Outlook.Application outlookApp)
|
||||
{
|
||||
@@ -70,7 +72,8 @@ namespace OutlookAddin.Services
|
||||
|
||||
try
|
||||
{
|
||||
CrmClient = new EspoCrmClient(baseUrl, creds.Username, creds.ApiKey, Logger);
|
||||
_httpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
|
||||
CrmClient = new EspoCrmClient(_httpClient, baseUrl.ToString(), creds.Username, creds.ApiKey, Logger);
|
||||
FilingService = new FilingService(CrmClient, RetryQueue, Logger);
|
||||
_retryProcessor = new RetryQueueProcessor(RetryQueue, CrmClient, Logger);
|
||||
_retryProcessor.Start();
|
||||
@@ -318,6 +321,7 @@ namespace OutlookAddin.Services
|
||||
public void Dispose()
|
||||
{
|
||||
try { _retryProcessor?.Dispose(); } catch { }
|
||||
try { _httpClient?.Dispose(); } catch { }
|
||||
try
|
||||
{
|
||||
Logger.Information("AddInHost shutting down");
|
||||
|
||||
Reference in New Issue
Block a user