-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a09ebef
commit f02de7f
Showing
11 changed files
with
197 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
|
||
namespace FluentMediator.Pipelines | ||
{ | ||
internal sealed class PipelineCollection<TPipeline> : IPipelineCollection<TPipeline> | ||
where TPipeline : class, ITypedPipeline | ||
where TPipeline : class, ITypedPipeline, INamedPipeline | ||
{ | ||
private readonly IDictionary<Type, TPipeline> _pipelines; | ||
private readonly IDictionary<Type, TPipeline> _typedPipelines; | ||
private readonly IDictionary<string, TPipeline> _namedPipelines; | ||
|
||
public PipelineCollection() | ||
{ | ||
_pipelines = new Dictionary<Type, TPipeline>(); | ||
_typedPipelines = new Dictionary<Type, TPipeline>(); | ||
_namedPipelines = new Dictionary<string, TPipeline>(); | ||
} | ||
|
||
public void Add(TPipeline pipeline) | ||
{ | ||
if (_pipelines.ContainsKey(pipeline.RequestType)) | ||
if (pipeline.Name is string) | ||
{ | ||
throw new PipelineAlreadyExistsException($"A pipeline for `{ pipeline.RequestType }` already exists."); | ||
_namedPipelines.Add(pipeline.Name, pipeline); | ||
} | ||
else | ||
{ | ||
if (_typedPipelines.ContainsKey(pipeline.RequestType)) | ||
{ | ||
throw new PipelineAlreadyExistsException($"A pipeline for `{ pipeline.RequestType }` already exists."); | ||
} | ||
_typedPipelines.Add(pipeline.RequestType, pipeline); | ||
} | ||
|
||
_pipelines.Add(pipeline.RequestType, pipeline); | ||
} | ||
|
||
public TPipeline Get(Type requestType) | ||
{ | ||
if (_pipelines.TryGetValue(requestType, out var pipeline)) | ||
if (_typedPipelines.TryGetValue(requestType, out var pipeline)) | ||
{ | ||
return pipeline; | ||
} | ||
|
||
throw new PipelineNotFoundException($"There is no pipeline configured for `{ requestType.GetType() }`."); | ||
} | ||
|
||
public bool Contains(Type requestType, out TPipeline? pipeline) | ||
public TPipeline Get(string pipelineName) | ||
{ | ||
if (!_pipelines.ContainsKey(requestType)) | ||
if (_namedPipelines.TryGetValue(pipelineName, out var pipeline)) | ||
{ | ||
pipeline = default; | ||
return false; | ||
return pipeline; | ||
} | ||
|
||
pipeline = _pipelines[requestType]; | ||
return true; | ||
} | ||
|
||
public IEnumerable<TPipeline> ToIEnumerable() | ||
{ | ||
return new ReadOnlyCollection<TPipeline>(_pipelines.Values.ToList()); | ||
throw new PipelineNotFoundException($"There is no pipeline configured for `{ pipelineName }`."); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters