I want to use a static proxy call method in the “program” method of the console, but an exception occurred. Tracing the source code, I found that
The ‘IAbpLazyService Provider’ in ‘Client Proxy Base’ is null
Is it because they are not in the same context? How should I solve it?
}
public class Program
{
public async static Task Main(string[] args)
{
using (var application = AbpApplicationFactory.Create<MyConsoleAppModule>())
{
application.Initialize();
var helloWorldService =
application.ServiceProvider.GetRequiredService<IWarningConfigAppService>();
if (helloWorldService != null)
{
var t = await helloWorldService.GetListAsync(new Q_WarningConfigDto());
}
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
}
}
}
I have already resolved it
public class Program
{
public async static Task Main(string[] args)
{
using (var application = AbpApplicationFactory.Create<HniotSWCMSConsoleModule>(options =>
{
options.Services.AddAutofacServiceProviderFactory();
}))
{
application.Initialize();
var currentTenant = application.ServiceProvider.GetRequiredService<ICurrentTenant>();
using (currentTenant.Change(Guid.Parse("3A05A2F9-6BF9-1165-0FDE-1981307AEF8C")))
{
var warningConfigAppService = application.ServiceProvider.GetRequiredService<IWarningConfigAppService>();
if (warningConfigAppService != null)
{
var result = await warningConfigAppService.GetListAsync(new Q_WarningConfigDto());
Console.WriteLine($"Result: {JsonSerializer.Serialize(result)}");
}
else
{
Console.WriteLine("Failed to resolve IWarningConfigAppService.");
}
}
Console.WriteLine("Press ENTER to stop application...");
Console.ReadLine();
application.Shutdown();
}
}
}