From 69104a6e14e8772868ea04051313ac9ef6b18767 Mon Sep 17 00:00:00 2001 From: Simon Gockner Date: Tue, 15 Oct 2019 14:27:32 +0200 Subject: [PATCH] close #22: return the registered `IRegistrationBase` --- .../Interfaces/IIocContainer.cs | 27 ++++--- LightweightIocContainer/IocContainer.cs | 72 ++++++++++++++----- .../LightweightIocContainer.xml | 18 +++++ 3 files changed, 90 insertions(+), 27 deletions(-) diff --git a/LightweightIocContainer/Interfaces/IIocContainer.cs b/LightweightIocContainer/Interfaces/IIocContainer.cs index d680ec4..be16027 100644 --- a/LightweightIocContainer/Interfaces/IIocContainer.cs +++ b/LightweightIocContainer/Interfaces/IIocContainer.cs @@ -27,14 +27,16 @@ namespace LightweightIocContainer.Interfaces /// The Interface to register /// The Type that implements the interface /// The for this - void Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface; + /// The created + IDefaultRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface; /// /// Register a without an interface/> /// /// The to register /// The for this - void Register(Lifestyle lifestyle = Lifestyle.Transient); + /// The created + IDefaultRegistration Register(Lifestyle lifestyle = Lifestyle.Transient); /// /// Register an Interface with a Type that implements it as a multiton/> @@ -42,7 +44,8 @@ namespace LightweightIocContainer.Interfaces /// The Interface to register /// The Type that implements the interface /// The Type of the multiton scope - void Register() where TImplementation : TInterface; + /// The created + IMultitonRegistration Register() where TImplementation : TInterface; /// /// Register an Interface with a Type that implements it/> @@ -50,14 +53,16 @@ namespace LightweightIocContainer.Interfaces /// The Interface to register /// The Type that implements the interface /// The for this - void Register(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient); + /// The created + IRegistrationBase Register(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient); /// /// Register a without an interface/> /// /// The to register /// The for this - void Register(Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient); + /// The created + IRegistrationBase Register(Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient); /// /// Register an Interface with a Type that implements it as a multiton/> @@ -65,26 +70,30 @@ namespace LightweightIocContainer.Interfaces /// The Interface to register /// The Type that implements the interface /// The Type of the multiton scope - void Register(Type tInterface, Type tImplementation, Type tScope); + /// The created + IRegistrationBase Register(Type tInterface, Type tImplementation, Type tScope); /// /// Register an Interface as an abstract typed factory/> /// /// The abstract typed factory to register - void RegisterFactory(); + /// The created + ITypedFactoryRegistration RegisterFactory(); /// /// Register an Interface as an abstract typed factory/> /// /// The abstract typed factory to register - void RegisterFactory(Type tFactory); + /// The created + IRegistrationBase RegisterFactory(Type tFactory); /// /// Register an Interface with an as a callback that is called when is called /// /// The Interface to register /// The for the callback - void RegisterUnitTestCallback(ResolveCallback unitTestCallback); + /// The created + IUnitTestCallbackRegistration RegisterUnitTestCallback(ResolveCallback unitTestCallback); /// /// Gets an instance of the given diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index f07bfbd..cb78a84 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -58,9 +58,13 @@ namespace LightweightIocContainer /// The Interface to register /// The Type that implements the interface /// The for this - public void Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface + /// The created + public IDefaultRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface { - Register(_registrationFactory.Register(lifestyle)); + IDefaultRegistration registration = _registrationFactory.Register(lifestyle); + Register(registration); + + return registration; } /// @@ -68,9 +72,13 @@ namespace LightweightIocContainer /// /// The to register /// The for this - public void Register(Lifestyle lifestyle = Lifestyle.Transient) + /// The created + public IDefaultRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) { - Register(_registrationFactory.Register(lifestyle)); + IDefaultRegistration registration = _registrationFactory.Register(lifestyle); + Register(registration); + + return registration; } /// @@ -79,9 +87,13 @@ namespace LightweightIocContainer /// The Interface to register /// The Type that implements the interface /// The Type of the multiton scope - public void Register() where TImplementation : TInterface + /// The created + public IMultitonRegistration Register() where TImplementation : TInterface { - Register(_registrationFactory.Register()); + IMultitonRegistration registration = _registrationFactory.Register(); + Register(registration); + + return registration; } /// @@ -90,9 +102,13 @@ namespace LightweightIocContainer /// The Interface to register /// The Type that implements the interface /// The for this - public void Register(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient) + /// The created + public IRegistrationBase Register(Type tInterface, Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient) { - Register(_registrationFactory.Register(tInterface, tImplementation, lifestyle)); + IRegistrationBase registration = _registrationFactory.Register(tInterface, tImplementation, lifestyle); + Register(registration); + + return registration; } /// @@ -100,9 +116,13 @@ namespace LightweightIocContainer /// /// The to register /// The for this - public void Register(Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient) + /// The created + public IRegistrationBase Register(Type tImplementation, Lifestyle lifestyle = Lifestyle.Transient) { - Register(_registrationFactory.Register(tImplementation, lifestyle)); + IRegistrationBase registration = _registrationFactory.Register(tImplementation, lifestyle); + Register(registration); + + return registration; } /// @@ -111,27 +131,39 @@ namespace LightweightIocContainer /// The Interface to register /// The Type that implements the interface /// The Type of the multiton scope - public void Register(Type tInterface, Type tImplementation, Type tScope) + /// The created + public IRegistrationBase Register(Type tInterface, Type tImplementation, Type tScope) { - Register(_registrationFactory.Register(tInterface, tImplementation, tScope)); + IRegistrationBase registration = _registrationFactory.Register(tInterface, tImplementation, tScope); + Register(registration); + + return registration; } /// /// Register an Interface as an abstract typed factory/> /// /// The abstract typed factory to register - public void RegisterFactory() + /// The created + public ITypedFactoryRegistration RegisterFactory() { - Register(_registrationFactory.RegisterFactory()); + ITypedFactoryRegistration registration = _registrationFactory.RegisterFactory(); + Register(registration); + + return registration; } /// /// Register an Interface as an abstract typed factory/> /// /// The abstract typed factory to register - public void RegisterFactory(Type tFactory) + /// The created + public IRegistrationBase RegisterFactory(Type tFactory) { - Register(_registrationFactory.RegisterFactory(tFactory)); + IRegistrationBase registration = _registrationFactory.RegisterFactory(tFactory); + Register(registration); + + return registration; } /// @@ -139,9 +171,13 @@ namespace LightweightIocContainer /// /// The Interface to register /// The for the callback - public void RegisterUnitTestCallback(ResolveCallback unitTestCallback) + /// The created + public IUnitTestCallbackRegistration RegisterUnitTestCallback(ResolveCallback unitTestCallback) { - Register(_registrationFactory.RegisterUnitTestCallback(unitTestCallback)); + IUnitTestCallbackRegistration registration = _registrationFactory.RegisterUnitTestCallback(unitTestCallback); + Register(registration); + + return registration; } /// diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml index 66412a6..74fab0b 100644 --- a/LightweightIocContainer/LightweightIocContainer.xml +++ b/LightweightIocContainer/LightweightIocContainer.xml @@ -224,6 +224,7 @@ The Interface to register The Type that implements the interface The for this + The created @@ -231,6 +232,7 @@ The to register The for this + The created @@ -239,6 +241,7 @@ The Interface to register The Type that implements the interface The Type of the multiton scope + The created @@ -247,6 +250,7 @@ The Interface to register The Type that implements the interface The for this + The created @@ -254,6 +258,7 @@ The to register The for this + The created @@ -262,18 +267,21 @@ The Interface to register The Type that implements the interface The Type of the multiton scope + The created Register an Interface as an abstract typed factory/> The abstract typed factory to register + The created Register an Interface as an abstract typed factory/> The abstract typed factory to register + The created @@ -281,6 +289,7 @@ The Interface to register The for the callback + The created @@ -441,6 +450,7 @@ The Interface to register The Type that implements the interface The for this + The created @@ -448,6 +458,7 @@ The to register The for this + The created @@ -456,6 +467,7 @@ The Interface to register The Type that implements the interface The Type of the multiton scope + The created @@ -464,6 +476,7 @@ The Interface to register The Type that implements the interface The for this + The created @@ -471,6 +484,7 @@ The to register The for this + The created @@ -479,18 +493,21 @@ The Interface to register The Type that implements the interface The Type of the multiton scope + The created Register an Interface as an abstract typed factory/> The abstract typed factory to register + The created Register an Interface as an abstract typed factory/> The abstract typed factory to register + The created @@ -498,6 +515,7 @@ The Interface to register The for the callback + The created