Added lifestyle parameters to SimpleInjectorDependencyResolver
This commit is contained in:
parent
1a5dcbf74d
commit
4ab6f67ea6
@ -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,7 +70,10 @@ namespace Tapeti.SimpleInjector
|
|||||||
|
|
||||||
public void RegisterController(Type type)
|
public void RegisterController(Type type)
|
||||||
{
|
{
|
||||||
container.Register(type);
|
if (controllersLifestyle != null)
|
||||||
|
container.Register(type, type, controllersLifestyle);
|
||||||
|
else
|
||||||
|
container.Register(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user