2025-02-25 00:45:13 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-10-01 22:41:07 -04:00
|
|
|
|
using meilisearch.NET;
|
|
|
|
|
using meilisearch.NET.Configurations;
|
|
|
|
|
using meilisearch.NET.Extensions;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static async Task Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
// Set security protocol to SystemDefault
|
|
|
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.SystemDefault;
|
2024-10-01 23:16:09 -04:00
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
// Configure and build the host
|
|
|
|
|
IHost host = CreateHostBuilder(args).Build();
|
2024-10-01 23:16:09 -04:00
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
//Resolve test dependency
|
|
|
|
|
var testService = host.Services.GetService<test>();
|
2024-10-01 23:16:09 -04:00
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
// Run the host
|
|
|
|
|
await host.RunAsync();
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-01 23:16:09 -04:00
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
|
|
|
Host.CreateDefaultBuilder(args)
|
|
|
|
|
.ConfigureAppConfiguration((hostingContext, configuration) =>
|
|
|
|
|
{
|
|
|
|
|
configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
|
|
|
|
configuration.AddEnvironmentVariables(); // Add environment variables as well (optional, but good practice)
|
|
|
|
|
configuration.AddCommandLine(args); // Support command line arguments
|
|
|
|
|
})
|
|
|
|
|
.ConfigureServices((hostContext, services) =>
|
|
|
|
|
{
|
|
|
|
|
services.AddMeiliSearchService();
|
|
|
|
|
services.AddSingleton<test>();
|
2024-10-01 23:16:09 -04:00
|
|
|
|
|
2025-02-25 00:45:13 -05:00
|
|
|
|
// Add logging configuration
|
|
|
|
|
services.AddLogging(builder =>
|
|
|
|
|
{
|
|
|
|
|
builder.ClearProviders();
|
|
|
|
|
builder.AddConsole();
|
|
|
|
|
builder.SetMinimumLevel(LogLevel.Information);
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.UseConsoleLifetime(options =>
|
|
|
|
|
{
|
|
|
|
|
options.SuppressStatusMessages = true; // This is optional: you can suppress the "Application started" message
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-01 22:41:07 -04:00
|
|
|
|
|
|
|
|
|
public class test
|
|
|
|
|
{
|
2025-02-25 00:45:13 -05:00
|
|
|
|
private readonly ILogger<test> _logger;
|
|
|
|
|
|
|
|
|
|
public test(MeilisearchService service, ILogger<test> logger)
|
2024-10-01 22:41:07 -04:00
|
|
|
|
{
|
2025-02-25 00:45:13 -05:00
|
|
|
|
|
|
|
|
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
|
|
|
|
|
|
|
|
|
// You can perform actions with the Meilisearch service here
|
|
|
|
|
_logger.LogInformation("Test service initialized.");
|
2024-10-01 22:41:07 -04:00
|
|
|
|
}
|
|
|
|
|
}
|