Merge branch 'release/1.1.0'
This commit is contained in:
commit
f658e90fc3
@ -7,10 +7,14 @@ namespace Tapeti.SimpleInjector
|
|||||||
public class SimpleInjectorDependencyResolver : IDependencyContainer
|
public class SimpleInjectorDependencyResolver : IDependencyContainer
|
||||||
{
|
{
|
||||||
private readonly Container container;
|
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.container = container;
|
||||||
|
this.defaultsLifestyle = defaultsLifestyle;
|
||||||
|
this.controllersLifestyle = controllersLifestyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Resolve<T>() where T : class
|
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
|
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>();
|
container.Register<TService, TImplementation>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RegisterDefault<TService>(Func<TService> factory) where TService : class
|
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);
|
container.Register(factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +70,9 @@ namespace Tapeti.SimpleInjector
|
|||||||
|
|
||||||
public void RegisterController(Type type)
|
public void RegisterController(Type type)
|
||||||
{
|
{
|
||||||
|
if (controllersLifestyle != null)
|
||||||
|
container.Register(type, type, controllersLifestyle);
|
||||||
|
else
|
||||||
container.Register(type);
|
container.Register(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,11 +8,11 @@ namespace Tapeti.Default
|
|||||||
public void Handle(IBindingContext context, Action next)
|
public void Handle(IBindingContext context, Action next)
|
||||||
{
|
{
|
||||||
if (context.Parameters.Count == 0)
|
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];
|
var parameter = context.Parameters[0];
|
||||||
if (!parameter.Info.ParameterType.IsClass)
|
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);
|
parameter.SetBinding(messageContext => messageContext.Message);
|
||||||
context.MessageClass = parameter.Info.ParameterType;
|
context.MessageClass = parameter.Info.ParameterType;
|
||||||
|
Loading…
Reference in New Issue
Block a user