-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix the tests and wrapper lines; broken as command processor and disp…
…atcher don't use yet.
- Loading branch information
Showing
137 changed files
with
2,347 additions
and
228 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
71 changes: 71 additions & 0 deletions
71
...aramore.Brighter.Extensions.DependencyInjection/ServiceProviderTransformerFactoryAsync.cs
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#region Licence | ||
/* The MIT License (MIT) | ||
Copyright © 2022 Ian Cooper <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. */ | ||
|
||
#endregion | ||
|
||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Paramore.Brighter.Extensions.DependencyInjection | ||
{ | ||
/// <summary> | ||
/// A factory for creating transformers, backed by the .NET Service Collection | ||
/// </summary> | ||
public class ServiceProviderTransformerFactoryAsync : IAmAMessageTransformerFactoryAsync | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
private readonly bool _isTransient; | ||
|
||
/// <summary> | ||
/// Constructs a transformer factory | ||
/// </summary> | ||
/// <param name="serviceProvider">The IoC container we use to satisfy requests for transforms</param> | ||
public ServiceProviderTransformerFactoryAsync(IServiceProvider serviceProvider) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
var options = serviceProvider.GetRequiredService<IBrighterOptions>(); | ||
if (options == null) _isTransient = false; else _isTransient = options.HandlerLifetime == ServiceLifetime.Transient; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a specific transformer on demand | ||
/// </summary> | ||
/// <param name="transformerType">The type of transformer to create</param> | ||
/// <returns></returns> | ||
public IAmAMessageTransformAsync Create(Type transformerType) | ||
{ | ||
return (IAmAMessageTransformAsync) _serviceProvider.GetService(transformerType); | ||
} | ||
|
||
/// <summary> | ||
/// If the transform was scoped as transient, we release it when the pipeline is finished | ||
/// </summary> | ||
/// <param name="transformer"></param> | ||
public void Release(IAmAMessageTransformAsync transformer) | ||
{ | ||
if (!_isTransient) return; | ||
|
||
var disposal = transformer as IDisposable; | ||
disposal?.Dispose(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#region Licence | ||
/* The MIT License (MIT) | ||
Copyright © 2014 Ian Cooper <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. */ | ||
|
||
#endregion | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Paramore.Brighter | ||
{ | ||
/// <summary> | ||
/// Interface IAmAMessageMapperAsync | ||
/// Map between a <see cref="Command"/> or an <see cref="Event"/> and a <see cref="Message"/>. You must implement this for each Command or Message you intend to send over | ||
/// a <a href="http://parlab.eecs.berkeley.edu/wiki/_media/patterns/taskqueue.pdf">Task Queue</a> | ||
/// </summary> | ||
public interface IAmAMessageMapperAsync { } | ||
|
||
/// <summary> | ||
/// Interface IAmAMessageMapperAsync | ||
/// Map between a <see cref="Command"/> or an <see cref="Event"/> and a <see cref="Message"/>. You must implement this for each Command or Message you intend to send over | ||
/// a <a href="http://parlab.eecs.berkeley.edu/wiki/_media/patterns/taskqueue.pdf">Task Queue</a> | ||
/// </summary> | ||
/// <typeparam name="TRequest">The type of the t request.</typeparam> | ||
public interface IAmAMessageMapperAsync<TRequest> : IAmAMessageMapperAsync where TRequest : class, IRequest | ||
{ | ||
/// <summary> | ||
/// Maps to message. | ||
/// </summary> | ||
/// <param name="request">The request.</param> | ||
/// <returns>Message.</returns> | ||
Task<Message> MapToMessage(TRequest request); | ||
/// <summary> | ||
/// Maps to request. | ||
/// </summary> | ||
/// <param name="message">The message.</param> | ||
/// <returns>TRequest.</returns> | ||
Task<TRequest> MapToRequest(Message message); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#region Licence | ||
/* The MIT License (MIT) | ||
Copyright © 2014 Ian Cooper <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. */ | ||
|
||
#endregion | ||
|
||
using System; | ||
|
||
namespace Paramore.Brighter | ||
{ | ||
/// <summary> | ||
/// Interface IAmAMessageMapperFactoryAsync | ||
/// In order to use a <a href="http://parlab.eecs.berkeley.edu/wiki/_media/patterns/taskqueue.pdf">Task Queue</a> approach we require you to provide | ||
/// a <see cref="IAmAMessageMapper"/> to map between <see cref="Command"/> or <see cref="Event"/> and a <see cref="Message"/> registered via <see cref="IAmAMessageMapperRegistry"/> | ||
/// We then call the instance of the factory which the client provides to create instances of that <see cref="IAmAMessageMapper"/>. You will need to implement the | ||
/// <see cref="IAmAMessageMapperFactory"/> to use the Task Queue approach, and provide the instance of your mapper on request. Typically you might use an IoC container | ||
/// to implement this. | ||
/// </summary> | ||
public interface IAmAMessageMapperFactoryAsync | ||
{ | ||
/// <summary> | ||
/// Creates the specified message mapper type. | ||
/// </summary> | ||
/// <param name="messageMapperType">Type of the message mapper.</param> | ||
/// <returns>IAmAMessageMapper.</returns> | ||
IAmAMessageMapperAsync Create(Type messageMapperType); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#region Licence | ||
/* The MIT License (MIT) | ||
Copyright © 2014 Ian Cooper <[email protected]> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. */ | ||
|
||
#endregion | ||
|
||
using System; | ||
|
||
namespace Paramore.Brighter | ||
{ | ||
/// <summary> | ||
/// Interface IAmAMessageMapperRegistryAsync | ||
/// In order to use a <a href="http://parlab.eecs.berkeley.edu/wiki/_media/patterns/taskqueue.pdf">Task Queue</a> approach we require you to provide | ||
/// a <see cref="IAmAMessageMapper"/> to map between <see cref="Command"/> or <see cref="Event"/> and a <see cref="Message"/> | ||
/// registered via <see cref="IAmAMessageMapperRegistry"/> | ||
/// The default implementation<see cref="MessageMapperRegistry"/> is suitable for most purposes and the interface is provided for testing | ||
/// </summary> | ||
public interface IAmAMessageMapperRegistryAsync | ||
{ | ||
/// <summary> | ||
/// Gets this instance. | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
/// <returns>IAmAMessageMapperAsync<T>.</returns> | ||
IAmAMessageMapperAsync<T> GetAsync<T>() where T : class, IRequest; | ||
/// <summary> | ||
/// Registers this instance. | ||
/// </summary> | ||
/// <typeparam name="TRequest">The type of the t request.</typeparam> | ||
/// <typeparam name="TMessageMapper">The type of the t message mapper.</typeparam> | ||
void RegisterAsync<TRequest, TMessageMapper>() where TRequest : class, IRequest where TMessageMapper : class, IAmAMessageMapperAsync<TRequest>; | ||
|
||
/// <summary> | ||
/// Registers this instance. | ||
/// </summary> | ||
/// <param name="request">The type of the request to map</param> | ||
/// <param name="mapper">The type of the mapper for this request</param> | ||
/// <exception cref="System.ArgumentException"></exception> | ||
void RegisterAsync(Type request, Type mapper); | ||
} | ||
} |
Oops, something went wrong.