1
0
mirror of synced 2024-11-16 23:03:50 +00:00
Tapeti/Tapeti.Flow.SQL/ConfigExtensions.cs

53 lines
1.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
using Tapeti.Config;
// ReSharper disable UnusedMember.Global
namespace Tapeti.Flow.SQL
{
/// <summary>
/// Extends ITapetiConfigBuilder to enable Flow SQL.
/// </summary>
public static class ConfigExtensions
{
/// <summary>
/// Enables the Flow SQL repository.
/// </summary>
/// <param name="config"></param>
/// <param name="connectionString"></param>
/// <param name="tableName"></param>
public static ITapetiConfigBuilder WithFlowSqlRepository(this ITapetiConfigBuilder config, string connectionString, string tableName = "Flow")
{
config.Use(new FlowSqlRepositoryExtension(connectionString, tableName));
return config;
}
}
internal class FlowSqlRepositoryExtension : ITapetiExtension
{
private readonly string connectionString;
2018-12-19 20:41:19 +00:00
private readonly string tableName;
public FlowSqlRepositoryExtension(string connectionString, string tableName)
{
this.connectionString = connectionString;
2018-12-19 20:41:19 +00:00
this.tableName = tableName;
}
public void RegisterDefaults(IDependencyContainer container)
{
2018-12-19 20:41:19 +00:00
container.RegisterDefaultSingleton<IFlowRepository>(() => new SqlConnectionFlowRepository(connectionString, tableName));
}
public IEnumerable<object> GetMiddleware(IDependencyResolver dependencyResolver)
{
return Enumerable.Empty<object>();
}
}
}