1
0
mirror of synced 2024-11-21 17:03:50 +00:00

Merge branch 'release/1.1.0'

This commit is contained in:
Mark van Renswoude 2019-01-07 16:54:52 +01:00
commit f658e90fc3
2 changed files with 23 additions and 6 deletions

View File

@ -7,10 +7,14 @@ namespace Tapeti.SimpleInjector
public class SimpleInjectorDependencyResolver : IDependencyContainer
{
private readonly Container container;
private readonly Lifestyle defaultsLifestyle;
private readonly Lifestyle controllersLifestyle;
public SimpleInjectorDependencyResolver(Container container)
public SimpleInjectorDependencyResolver(Container container, Lifestyle defaultsLifestyle = null, Lifestyle controllersLifestyle = null)
{
this.container = container;
this.defaultsLifestyle = defaultsLifestyle;
this.controllersLifestyle = controllersLifestyle;
}
public T Resolve<T>() where T : class
@ -26,13 +30,23 @@ namespace Tapeti.SimpleInjector
public void RegisterDefault<TService, TImplementation>() where TService : class where TImplementation : class, TService
{
if (CanRegisterDefault<TService>())
if (!CanRegisterDefault<TService>())
return;
if (defaultsLifestyle != null)
container.Register<TService, TImplementation>(defaultsLifestyle);
else
container.Register<TService, TImplementation>();
}
public void RegisterDefault<TService>(Func<TService> factory) where TService : class
{
if (CanRegisterDefault<TService>())
if (!CanRegisterDefault<TService>())
return;
if (defaultsLifestyle != null)
container.Register(factory, defaultsLifestyle);
else
container.Register(factory);
}
@ -56,7 +70,10 @@ namespace Tapeti.SimpleInjector
public void RegisterController(Type type)
{
container.Register(type);
if (controllersLifestyle != null)
container.Register(type, type, controllersLifestyle);
else
container.Register(type);
}

View File

@ -8,11 +8,11 @@ namespace Tapeti.Default
public void Handle(IBindingContext context, Action next)
{
if (context.Parameters.Count == 0)
throw new TopologyConfigurationException("First parameter must be a message class");
throw new TopologyConfigurationException($"First parameter of method {context.Method.Name} in controller {context.Method.DeclaringType?.Name} must be a message class");
var parameter = context.Parameters[0];
if (!parameter.Info.ParameterType.IsClass)
throw new TopologyConfigurationException($"First parameter {parameter.Info.Name} must be a message class");
throw new TopologyConfigurationException($"First parameter {parameter.Info.Name} of method {context.Method.Name} in controller {context.Method.DeclaringType?.Name} must be a message class");
parameter.SetBinding(messageContext => messageContext.Message);
context.MessageClass = parameter.Info.ParameterType;