From e06a631700deb632a75e582180fbddd52dcc9154 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Tue, 7 Feb 2017 18:22:28 +0100 Subject: [PATCH] Renamed IMiddlewareBundle to ITapetiExtension --- Tapeti.Flow.SQL/ConfigExtensions.cs | 36 ++++++++++++ Tapeti.Flow.SQL/Properties/AssemblyInfo.cs | 36 ++++++++++++ Tapeti.Flow.SQL/Tapeti.Flow.SQL.csproj | 65 ++++++++++++++++++++++ Tapeti.Flow/FlowMiddleware.cs | 21 +++---- Tapeti.sln | 6 ++ Tapeti/Config/IMiddlewareBundle.cs | 9 --- Tapeti/Config/ITapetiExtension.cs | 11 ++++ Tapeti/Tapeti.csproj | 2 +- Tapeti/TapetiConfig.cs | 28 +++++++--- Test/Program.cs | 2 + 10 files changed, 185 insertions(+), 31 deletions(-) create mode 100644 Tapeti.Flow.SQL/ConfigExtensions.cs create mode 100644 Tapeti.Flow.SQL/Properties/AssemblyInfo.cs create mode 100644 Tapeti.Flow.SQL/Tapeti.Flow.SQL.csproj delete mode 100644 Tapeti/Config/IMiddlewareBundle.cs create mode 100644 Tapeti/Config/ITapetiExtension.cs diff --git a/Tapeti.Flow.SQL/ConfigExtensions.cs b/Tapeti.Flow.SQL/ConfigExtensions.cs new file mode 100644 index 0000000..686ef9e --- /dev/null +++ b/Tapeti.Flow.SQL/ConfigExtensions.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using Tapeti.Config; + +namespace Tapeti.Flow.SQL +{ + public static class ConfigExtensions + { + public static TapetiConfig WithFlowSqlRepository(this TapetiConfig config) + { + config.Use(new FlowSqlRepositoryBundle()); + return config; + } + } + + + internal class FlowSqlRepositoryBundle : ITapetiExtension + { + /* + public IEnumerable GetContents(IDependencyResolver dependencyResolver) + { + ((IDependencyContainer)dependencyResolver)?.RegisterDefault(); + + return null; + } + */ + + public void RegisterDefaults(IDependencyContainer container) + { + } + + public IEnumerable GetMiddleware(IDependencyResolver dependencyResolver) + { + return null; + } + } +} diff --git a/Tapeti.Flow.SQL/Properties/AssemblyInfo.cs b/Tapeti.Flow.SQL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5dce38b --- /dev/null +++ b/Tapeti.Flow.SQL/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Tapeti.Flow.SQL")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Tapeti.Flow.SQL")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6de7b122-eb6a-46b8-aeaf-f84dde18f9c7")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Tapeti.Flow.SQL/Tapeti.Flow.SQL.csproj b/Tapeti.Flow.SQL/Tapeti.Flow.SQL.csproj new file mode 100644 index 0000000..151e970 --- /dev/null +++ b/Tapeti.Flow.SQL/Tapeti.Flow.SQL.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7} + Library + Properties + Tapeti.Flow.SQL + Tapeti.Flow.SQL + v4.6.1 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + {f84ad920-d5a1-455d-aed5-2542b3a47b85} + Tapeti.Flow + + + {8ab4fd33-4aaa-465c-8579-9db3f3b23813} + Tapeti + + + + + \ No newline at end of file diff --git a/Tapeti.Flow/FlowMiddleware.cs b/Tapeti.Flow/FlowMiddleware.cs index 6e696d8..16e4589 100644 --- a/Tapeti.Flow/FlowMiddleware.cs +++ b/Tapeti.Flow/FlowMiddleware.cs @@ -4,21 +4,18 @@ using Tapeti.Flow.Default; namespace Tapeti.Flow { - public class FlowMiddleware : IMiddlewareBundle + public class FlowMiddleware : ITapetiExtension { - public IEnumerable GetContents(IDependencyResolver dependencyResolver) + public void RegisterDefaults(IDependencyContainer container) { - var container = dependencyResolver as IDependencyContainer; - - // ReSharper disable once InvertIf - if (container != null) - { - container.RegisterDefault(); - container.RegisterDefault(); - container.RegisterDefault(); - container.RegisterDefault(); - } + container.RegisterDefault(); + container.RegisterDefault(); + container.RegisterDefault(); + container.RegisterDefault(); + } + public IEnumerable GetMiddleware(IDependencyResolver dependencyResolver) + { return new[] { new FlowBindingMiddleware() }; } } diff --git a/Tapeti.sln b/Tapeti.sln index 3da81b6..b04e494 100644 --- a/Tapeti.sln +++ b/Tapeti.sln @@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tapeti.Flow", "Tapeti.Flow\Tapeti.Flow.csproj", "{F84AD920-D5A1-455D-AED5-2542B3A47B85}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tapeti.Flow.SQL", "Tapeti.Flow.SQL\Tapeti.Flow.SQL.csproj", "{6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {F84AD920-D5A1-455D-AED5-2542B3A47B85}.Debug|Any CPU.Build.0 = Debug|Any CPU {F84AD920-D5A1-455D-AED5-2542B3A47B85}.Release|Any CPU.ActiveCfg = Release|Any CPU {F84AD920-D5A1-455D-AED5-2542B3A47B85}.Release|Any CPU.Build.0 = Release|Any CPU + {6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Tapeti/Config/IMiddlewareBundle.cs b/Tapeti/Config/IMiddlewareBundle.cs deleted file mode 100644 index 82846f3..0000000 --- a/Tapeti/Config/IMiddlewareBundle.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; - -namespace Tapeti.Config -{ - public interface IMiddlewareBundle - { - IEnumerable GetContents(IDependencyResolver dependencyResolver); - } -} diff --git a/Tapeti/Config/ITapetiExtension.cs b/Tapeti/Config/ITapetiExtension.cs new file mode 100644 index 0000000..6bc6f6c --- /dev/null +++ b/Tapeti/Config/ITapetiExtension.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; + +namespace Tapeti.Config +{ + public interface ITapetiExtension + { + void RegisterDefaults(IDependencyContainer container); + + IEnumerable GetMiddleware(IDependencyResolver dependencyResolver); + } +} diff --git a/Tapeti/Tapeti.csproj b/Tapeti/Tapeti.csproj index d8794ea..7fbad18 100644 --- a/Tapeti/Tapeti.csproj +++ b/Tapeti/Tapeti.csproj @@ -74,7 +74,7 @@ - + diff --git a/Tapeti/TapetiConfig.cs b/Tapeti/TapetiConfig.cs index 5dcbdc7..1d6d81c 100644 --- a/Tapeti/TapetiConfig.cs +++ b/Tapeti/TapetiConfig.cs @@ -82,17 +82,27 @@ namespace Tapeti } - public TapetiConfig Use(IMiddlewareBundle bundle) + public TapetiConfig Use(ITapetiExtension extension) { - foreach (var middleware in bundle.GetContents(dependencyResolver)) + var container = dependencyResolver as IDependencyContainer; + if (container != null) + extension.RegisterDefaults(container); + + var middlewareBundle = extension.GetMiddleware(dependencyResolver); + + // ReSharper disable once InvertIf + if (middlewareBundle != null) { - // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull - if (middleware is IBindingMiddleware) - Use((IBindingMiddleware) middleware); - else if (middleware is IMessageMiddleware) - Use((IMessageMiddleware)middleware); - else - throw new ArgumentException($"Unsupported middleware implementation: {middleware.GetType().Name}"); + foreach (var middleware in middlewareBundle) + { + // ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull + if (middleware is IBindingMiddleware) + Use((IBindingMiddleware)middleware); + else if (middleware is IMessageMiddleware) + Use((IMessageMiddleware)middleware); + else + throw new ArgumentException($"Unsupported middleware implementation: {middleware.GetType().Name}"); + } } return this; diff --git a/Test/Program.cs b/Test/Program.cs index 1e575a2..9f20a3c 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -17,6 +17,8 @@ namespace Test container.Register(); container.Register(); + container.Register(); + var config = new TapetiConfig(new SimpleInjectorDependencyResolver(container)) .WithFlow() .RegisterAllControllers()