1
0
mirror of synced 2024-11-14 06:29:17 +00:00

Renamed IMiddlewareBundle to ITapetiExtension

This commit is contained in:
Mark van Renswoude 2017-02-07 18:22:28 +01:00
parent 66fbcf2427
commit 1f41f6bcc0
10 changed files with 185 additions and 31 deletions

View File

@ -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<object> GetContents(IDependencyResolver dependencyResolver)
{
((IDependencyContainer)dependencyResolver)?.RegisterDefault<IFlowRepository, >();
return null;
}
*/
public void RegisterDefaults(IDependencyContainer container)
{
}
public IEnumerable<object> GetMiddleware(IDependencyResolver dependencyResolver)
{
return null;
}
}
}

View File

@ -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")]

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{6DE7B122-EB6A-46B8-AEAF-F84DDE18F9C7}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Tapeti.Flow.SQL</RootNamespace>
<AssemblyName>Tapeti.Flow.SQL</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tapeti.Flow\Tapeti.Flow.csproj">
<Project>{f84ad920-d5a1-455d-aed5-2542b3a47b85}</Project>
<Name>Tapeti.Flow</Name>
</ProjectReference>
<ProjectReference Include="..\Tapeti\Tapeti.csproj">
<Project>{8ab4fd33-4aaa-465c-8579-9db3f3b23813}</Project>
<Name>Tapeti</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -4,14 +4,9 @@ using Tapeti.Flow.Default;
namespace Tapeti.Flow
{
public class FlowMiddleware : IMiddlewareBundle
public class FlowMiddleware : ITapetiExtension
{
public IEnumerable<object> GetContents(IDependencyResolver dependencyResolver)
{
var container = dependencyResolver as IDependencyContainer;
// ReSharper disable once InvertIf
if (container != null)
public void RegisterDefaults(IDependencyContainer container)
{
container.RegisterDefault<IFlowProvider, FlowProvider>();
container.RegisterDefault<IFlowHandler, FlowProvider>();
@ -19,6 +14,8 @@ namespace Tapeti.Flow
container.RegisterDefault<IFlowStore, FlowStore>();
}
public IEnumerable<object> GetMiddleware(IDependencyResolver dependencyResolver)
{
return new[] { new FlowBindingMiddleware() };
}
}

View File

@ -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

View File

@ -1,9 +0,0 @@
using System.Collections.Generic;
namespace Tapeti.Config
{
public interface IMiddlewareBundle
{
IEnumerable<object> GetContents(IDependencyResolver dependencyResolver);
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
namespace Tapeti.Config
{
public interface ITapetiExtension
{
void RegisterDefaults(IDependencyContainer container);
IEnumerable<object> GetMiddleware(IDependencyResolver dependencyResolver);
}
}

View File

@ -74,7 +74,7 @@
<Compile Include="ILogger.cs" />
<Compile Include="Config\IMessageContext.cs" />
<Compile Include="Config\IMessageMiddleware.cs" />
<Compile Include="Config\IMiddlewareBundle.cs" />
<Compile Include="Config\ITapetiExtension.cs" />
<Compile Include="Config\IConfig.cs" />
<Compile Include="MessageController.cs" />
<Compile Include="Config\IBindingMiddleware.cs" />

View File

@ -82,18 +82,28 @@ 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)
{
foreach (var middleware in middlewareBundle)
{
// ReSharper disable once CanBeReplacedWithTryCastAndCheckForNull
if (middleware is IBindingMiddleware)
Use((IBindingMiddleware) middleware);
Use((IBindingMiddleware)middleware);
else if (middleware is IMessageMiddleware)
Use((IMessageMiddleware)middleware);
else
throw new ArgumentException($"Unsupported middleware implementation: {middleware.GetType().Name}");
}
}
return this;
}

View File

@ -17,6 +17,8 @@ namespace Test
container.Register<MarcoEmitter>();
container.Register<Visualizer>();
container.Register<IFlowRepository>();
var config = new TapetiConfig(new SimpleInjectorDependencyResolver(container))
.WithFlow()
.RegisterAllControllers()