2017-02-07 18:22:28 +01:00
|
|
|
|
using System.Collections.Generic;
|
2022-11-23 09:13:38 +01:00
|
|
|
|
using System.Linq;
|
2017-02-07 18:22:28 +01:00
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
2018-12-19 20:50:56 +01:00
|
|
|
|
// ReSharper disable UnusedMember.Global
|
|
|
|
|
|
2017-02-07 18:22:28 +01:00
|
|
|
|
namespace Tapeti.Flow.SQL
|
|
|
|
|
{
|
2019-08-14 12:20:53 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Extends ITapetiConfigBuilder to enable Flow SQL.
|
|
|
|
|
/// </summary>
|
2017-02-07 18:22:28 +01:00
|
|
|
|
public static class ConfigExtensions
|
|
|
|
|
{
|
2019-08-14 12:20:53 +02:00
|
|
|
|
/// <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")
|
2017-02-07 18:22:28 +01:00
|
|
|
|
{
|
2019-08-14 12:20:53 +02:00
|
|
|
|
config.Use(new FlowSqlRepositoryExtension(connectionString, tableName));
|
2017-02-07 18:22:28 +01:00
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 12:20:53 +02:00
|
|
|
|
internal class FlowSqlRepositoryExtension : ITapetiExtension
|
2017-02-07 18:22:28 +01:00
|
|
|
|
{
|
2017-02-08 15:52:24 +01:00
|
|
|
|
private readonly string connectionString;
|
2018-12-19 21:41:19 +01:00
|
|
|
|
private readonly string tableName;
|
2017-02-07 18:22:28 +01:00
|
|
|
|
|
2017-02-08 15:52:24 +01:00
|
|
|
|
|
2019-08-14 12:20:53 +02:00
|
|
|
|
public FlowSqlRepositoryExtension(string connectionString, string tableName)
|
2017-02-08 15:52:24 +01:00
|
|
|
|
{
|
|
|
|
|
this.connectionString = connectionString;
|
2018-12-19 21:41:19 +01:00
|
|
|
|
this.tableName = tableName;
|
2017-02-07 18:22:28 +01:00
|
|
|
|
}
|
2017-02-08 15:52:24 +01:00
|
|
|
|
|
2017-02-07 18:22:28 +01:00
|
|
|
|
|
|
|
|
|
public void RegisterDefaults(IDependencyContainer container)
|
|
|
|
|
{
|
2018-12-19 21:41:19 +01:00
|
|
|
|
container.RegisterDefaultSingleton<IFlowRepository>(() => new SqlConnectionFlowRepository(connectionString, tableName));
|
2017-02-07 18:22:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 15:52:24 +01:00
|
|
|
|
|
2017-02-07 18:22:28 +01:00
|
|
|
|
public IEnumerable<object> GetMiddleware(IDependencyResolver dependencyResolver)
|
|
|
|
|
{
|
2022-11-23 09:13:38 +01:00
|
|
|
|
return Enumerable.Empty<object>();
|
2017-02-07 18:22:28 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|