using Microsoft.Extensions.DependencyInjection;
using Serilog.Ui.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Serilog.Ui.SqliteDataProvider
{
///
/// Sqlite data provider specific extension methods for .
///
public static class SerilogUiOptionBuilderExtensions
{
///
/// Configures the SerilogUi to connect to a Sqlite database.
///
/// The options builder.
/// The connection string.
/// Name of the table.
/// throw if connectionString is null
/// throw is tableName is null
public static void UseSqliteServer(
this SerilogUiOptionsBuilder optionsBuilder,
string connectionString,
string tableName
)
{
if (string.IsNullOrWhiteSpace(connectionString))
throw new ArgumentNullException(nameof(connectionString));
if (string.IsNullOrWhiteSpace(tableName))
throw new ArgumentNullException(nameof(tableName));
var relationProvider = new RelationalDbOptions
{
ConnectionString = connectionString,
TableName = tableName
};
((ISerilogUiOptionsBuilder)optionsBuilder).Services
.AddScoped(p => ActivatorUtilities.CreateInstance(p, relationProvider));
}
}
}