2016-12-11 14:08:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Default
|
|
|
|
|
{
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Attempts to resolve any unhandled parameters to Controller methods using the IoC container.
|
|
|
|
|
/// This middleware is included by default in the standard TapetiConfig.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DependencyResolverBinding : IControllerBindingMiddleware
|
2016-12-11 14:08:58 +00:00
|
|
|
|
{
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public void Handle(IControllerBindingContext context, Action next)
|
2016-12-11 14:08:58 +00:00
|
|
|
|
{
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
|
|
foreach (var parameter in context.Parameters.Where(p => !p.HasBinding && p.Info.ParameterType.IsClass))
|
2019-08-13 18:30:04 +00:00
|
|
|
|
parameter.SetBinding(messageContext => messageContext.Config.DependencyResolver.Resolve(parameter.Info.ParameterType));
|
2016-12-11 14:08:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|