Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

解决中间件排序问题 #138

Merged
merged 1 commit into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions src/SmartSql.Test.Unit/PipelineBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,28 @@ public class PipelineBuilderTest
[Fact]
public void Build()
{
//var pipeline = new PipelineBuilder()
// .Add(new InitializerMiddleware())
// .Add(new PrepareStatementMiddleware())
// .Add(new CachingMiddleware())
// .Add(new CommandExecuterMiddleware(new CommandExecuter()))
// .Add(new ResultHandlerMiddleware())
// .Build();
var pipeline = new PipelineBuilder()
.Add(new ResultHandlerMiddleware())
.Add(new PrepareStatementMiddleware())
.Add(new InitializerMiddleware())
.Add(new CachingMiddleware())
.Add(new CommandExecuterMiddleware())
.Add(new DataSourceFilterMiddleware())
.Add(new TransactionMiddleware())
.Build();
Assert.Equal(typeof(InitializerMiddleware), pipeline.GetType());
IMiddleware middleware = pipeline.Next;
Assert.Equal(typeof(PrepareStatementMiddleware), middleware.GetType());
middleware = middleware.Next;
Assert.Equal(typeof(CachingMiddleware), middleware.GetType());
middleware = middleware.Next;
Assert.Equal(typeof(TransactionMiddleware), middleware.GetType());
middleware = middleware.Next;
Assert.Equal(typeof(DataSourceFilterMiddleware), middleware.GetType());
middleware = middleware.Next;
Assert.Equal(typeof(CommandExecuterMiddleware), middleware.GetType());
middleware = middleware.Next;
Assert.Equal(typeof(ResultHandlerMiddleware), middleware.GetType());
}
}
}
8 changes: 4 additions & 4 deletions src/SmartSql/PipelineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ public IMiddleware Build()
var list = Pipeline.OrderBy(middleware => middleware.Order).ToList();
for (var i = 0; i < list.Count; i++)
{
var current = Pipeline[i];
if (i == Pipeline.Count - 1)
var current = list[i];
if (i == list.Count - 1)
{
break;
}

current.Next = Pipeline[i + 1];
current.Next = list[i + 1];
}

return Pipeline.FirstOrDefault();
return list.FirstOrDefault();
}
}
}