From 4ab6f67ea6528cdb30ea6f957c35fca56d82b79e Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Fri, 28 Dec 2018 15:34:58 +0100 Subject: [PATCH] Added lifestyle parameters to SimpleInjectorDependencyResolver --- .../SimpleInjectorDependencyResolver.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Tapeti.SimpleInjector/SimpleInjectorDependencyResolver.cs b/Tapeti.SimpleInjector/SimpleInjectorDependencyResolver.cs index ad8180e..7daacaf 100644 --- a/Tapeti.SimpleInjector/SimpleInjectorDependencyResolver.cs +++ b/Tapeti.SimpleInjector/SimpleInjectorDependencyResolver.cs @@ -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() where T : class @@ -26,13 +30,23 @@ namespace Tapeti.SimpleInjector public void RegisterDefault() where TService : class where TImplementation : class, TService { - if (CanRegisterDefault()) + if (!CanRegisterDefault()) + return; + + if (defaultsLifestyle != null) + container.Register(defaultsLifestyle); + else container.Register(); } public void RegisterDefault(Func factory) where TService : class { - if (CanRegisterDefault()) + if (!CanRegisterDefault()) + 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); }