diff --git a/LightweightIocContainer/Interfaces/IIocContainer.cs b/LightweightIocContainer/Interfaces/IIocContainer.cs index 01dc6e9..fba5b84 100644 --- a/LightweightIocContainer/Interfaces/IIocContainer.cs +++ b/LightweightIocContainer/Interfaces/IIocContainer.cs @@ -39,6 +39,42 @@ namespace LightweightIocContainer.Interfaces /// The created IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface2, TInterface1; + /// + /// Register multiple interfaces for a that implements them + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// The that implements both interfaces + /// The for this + /// The created + IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface3, TInterface2, TInterface1; + + /// + /// Register multiple interfaces for a that implements them + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// A fourth interface to register + /// The that implements both interfaces + /// The for this + /// The created + IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface4, TInterface3, TInterface2, TInterface1; + + /// + /// Register multiple interfaces for a that implements them + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// A fourth interface to register + /// A fifth interface to register + /// The that implements both interfaces + /// The for this + /// The created + IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface5, TInterface4, TInterface3, TInterface2, TInterface1; + /// /// Register a without an interface /// diff --git a/LightweightIocContainer/Interfaces/Registrations/FluentProviders/IOnCreate.cs b/LightweightIocContainer/Interfaces/Registrations/FluentProviders/IOnCreate.cs index 5f1db43..d32a4b3 100644 --- a/LightweightIocContainer/Interfaces/Registrations/FluentProviders/IOnCreate.cs +++ b/LightweightIocContainer/Interfaces/Registrations/FluentProviders/IOnCreate.cs @@ -42,4 +42,64 @@ namespace LightweightIocContainer.Interfaces.Registrations.FluentProviders /// The current instance of this IMultipleRegistration OnCreate(Action action1, Action action2); } + + /// + /// Provides an method to an + /// + /// The first registered interface + /// The second registered interface + /// The third registered interface + public interface IOnCreate + { + /// + /// Pass an for each interface that will be invoked when instances of the types are created + /// + /// The first + /// The second + /// The third + /// The current instance of this + IMultipleRegistration OnCreate(Action action1, Action action2, Action action3); + } + + /// + /// Provides an method to an + /// + /// The first registered interface + /// The second registered interface + /// The third registered interface + /// The fourth registered interface + public interface IOnCreate + { + /// + /// Pass an for each interface that will be invoked when instances of the types are created + /// + /// The first + /// The second + /// The third + /// The fourth + /// The current instance of this + IMultipleRegistration OnCreate(Action action1, Action action2, Action action3, Action action4); + } + + /// + /// Provides an method to an + /// + /// The first registered interface + /// The second registered interface + /// The third registered interface + /// The fourth registered interface + /// The fifth registered interface + public interface IOnCreate + { + /// + /// Pass an for each interface that will be invoked when instances of the types are created + /// + /// The first + /// The second + /// The third + /// The fourth + /// The fifth + /// The current instance of this + IMultipleRegistration OnCreate(Action action1, Action action2, Action action3, Action action4, Action action5); + } } \ No newline at end of file diff --git a/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs b/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs index 99c4b0c..d1b4cbe 100644 --- a/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs +++ b/LightweightIocContainer/Interfaces/Registrations/IMultipleRegistration.cs @@ -8,15 +8,60 @@ using LightweightIocContainer.Interfaces.Registrations.FluentProviders; namespace LightweightIocContainer.Interfaces.Registrations { /// - /// An to register multiple interfaces for on implementation type + /// The base interface for every to register multiple interfaces /// /// The first interface - /// The second interface - public interface IMultipleRegistration : ITypedRegistrationBase, IOnCreate + public interface IMultipleRegistration : ITypedRegistrationBase { /// - /// A of s that are registered within this + /// A of s that are registered within this /// List Registrations { get; } } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + public interface IMultipleRegistration : IMultipleRegistration, IOnCreate + { + + } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + /// The third interface + public interface IMultipleRegistration : IMultipleRegistration, IOnCreate + { + + } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + /// The third interface + /// The fourth interface + public interface IMultipleRegistration : IMultipleRegistration, IOnCreate + { + + } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + /// The third interface + /// The fourth interface + /// The fifth interface + public interface IMultipleRegistration : IMultipleRegistration, IOnCreate + { + + } } \ No newline at end of file diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index 45666d3..4383d68 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -79,11 +79,64 @@ namespace LightweightIocContainer public IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface2, TInterface1 { IMultipleRegistration multipleRegistration = _registrationFactory.Register(lifestyle); + Register(multipleRegistration); - foreach (var registration in multipleRegistration.Registrations) - { - Register(registration); - } + return multipleRegistration; + } + + /// + /// Register multiple interfaces for a that implements them + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// The that implements both interfaces + /// The for this + /// The created + public IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface3, TInterface2, TInterface1 + { + IMultipleRegistration multipleRegistration = + _registrationFactory.Register(lifestyle); + Register(multipleRegistration); + + return multipleRegistration; + } + + /// + /// Register multiple interfaces for a that implements them + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// A fourth interface to register + /// The that implements both interfaces + /// The for this + /// The created + public IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface4, TInterface3, TInterface2, TInterface1 + { + IMultipleRegistration multipleRegistration = + _registrationFactory.Register(lifestyle); + Register(multipleRegistration); + + return multipleRegistration; + } + + /// + /// Register multiple interfaces for a that implements them + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// A fourth interface to register + /// A fifth interface to register + /// The that implements both interfaces + /// The for this + /// The created + public IMultipleRegistration Register(Lifestyle lifestyle = Lifestyle.Transient) where TImplementation : TInterface5, TInterface4, TInterface3, TInterface2, TInterface1 + { + IMultipleRegistration multipleRegistration = + _registrationFactory.Register(lifestyle); + Register(multipleRegistration); return multipleRegistration; } @@ -159,6 +212,19 @@ namespace LightweightIocContainer _registrations.Add(registration); } + /// + /// Register all from an + /// + /// The of the first registered interface + /// The + private void Register(IMultipleRegistration multipleRegistration) + { + foreach (var registration in multipleRegistration.Registrations) + { + Register(registration); + } + } + /// /// Gets an instance of the given /// diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml index b4d7ba8..04f14cb 100644 --- a/LightweightIocContainer/LightweightIocContainer.xml +++ b/LightweightIocContainer/LightweightIocContainer.xml @@ -356,6 +356,42 @@ The for this The created + + + Register multiple interfaces for a that implements them + + The base interface to register + A second interface to register + A third interface to register + The that implements both interfaces + The for this + The created + + + + Register multiple interfaces for a that implements them + + The base interface to register + A second interface to register + A third interface to register + A fourth interface to register + The that implements both interfaces + The for this + The created + + + + Register multiple interfaces for a that implements them + + The base interface to register + A second interface to register + A third interface to register + A fourth interface to register + A fifth interface to register + The that implements both interfaces + The for this + The created + Register a without an interface @@ -471,6 +507,63 @@ The second The current instance of this + + + Provides an method to an + + The first registered interface + The second registered interface + The third registered interface + + + + Pass an for each interface that will be invoked when instances of the types are created + + The first + The second + The third + The current instance of this + + + + Provides an method to an + + The first registered interface + The second registered interface + The third registered interface + The fourth registered interface + + + + Pass an for each interface that will be invoked when instances of the types are created + + The first + The second + The third + The fourth + The current instance of this + + + + Provides an method to an + + The first registered interface + The second registered interface + The third registered interface + The fourth registered interface + The fifth registered interface + + + + Pass an for each interface that will be invoked when instances of the types are created + + The first + The second + The third + The fourth + The fifth + The current instance of this + Provides a method to an @@ -507,6 +600,17 @@ The of the interface + + + The base interface for every to register multiple interfaces + + The first interface + + + + A of s that are registered within this + + An to register multiple interfaces for on implementation type @@ -514,10 +618,32 @@ The first interface The second interface - + + + An to register multiple interfaces for on implementation type + + The first interface + The second interface + The third interface + + + + An to register multiple interfaces for on implementation type + + The first interface + The second interface + The third interface + The fourth interface + + - A of s that are registered within this + An to register multiple interfaces for on implementation type + The first interface + The second interface + The third interface + The fourth interface + The fifth interface @@ -647,6 +773,42 @@ The for this The created + + + Register multiple interfaces for a that implements them + + The base interface to register + A second interface to register + A third interface to register + The that implements both interfaces + The for this + The created + + + + Register multiple interfaces for a that implements them + + The base interface to register + A second interface to register + A third interface to register + A fourth interface to register + The that implements both interfaces + The for this + The created + + + + Register multiple interfaces for a that implements them + + The base interface to register + A second interface to register + A third interface to register + A fourth interface to register + A fifth interface to register + The that implements both interfaces + The for this + The created + Register a without an interface @@ -686,6 +848,13 @@ The given The is already registered in this + + + Register all from an + + The of the first registered interface + The + Gets an instance of the given @@ -838,6 +1007,25 @@ The The current instance of this + + + The base class for every to register multiple interfaces + + The first interface + + + + The base class for every to register multiple interfaces + + The of the first interface + The of the implementation + The of this + + + + A of s that are registered within this + + An to register multiple interfaces for on implementation type @@ -854,17 +1042,102 @@ The of the implementation The of this - + - A of s that are registered within this + Pass an for each interface that will be invoked when instances of the types are created + The first + The second + The current instance of this - + + + An to register multiple interfaces for on implementation type + + The first interface + The second interface + The third interface + + + + An to register multiple interfaces for on implementation type + + The of the first interface + The of the second interface + The of the third interface + The of the implementation + The of this + + Pass an for each interface that will be invoked when instances of the types are created The first The second + The third + The current instance of this + + + + An to register multiple interfaces for on implementation type + + The first interface + The second interface + The third interface + The fourth interface + + + + An to register multiple interfaces for on implementation type + + The of the first interface + The of the second interface + The of the third interface + The of the fourth interface + The of the implementation + The of this + + + + Pass an for each interface that will be invoked when instances of the types are created + + The first + The second + The third + The fourth + The current instance of this + + + + An to register multiple interfaces for on implementation type + + The first interface + The second interface + The third interface + The fourth interface + The fifth interface + + + + An to register multiple interfaces for on implementation type + + The of the first interface + The of the second interface + The of the third interface + The of the fourth interface + The of the fifth interface + The of the implementation + The of this + + + + Pass an for each interface that will be invoked when instances of the types are created + + The first + The second + The third + The fourth + The fifth The current instance of this @@ -962,6 +1235,42 @@ The for this The created + + + Register multiple interfaces for a that implements them and create a + + The base interface to register + A second interface to register + A third interface to register + The that implements both interfaces + The for this + The created + + + + Register multiple interfaces for a that implements them and create a + + The base interface to register + A second interface to register + A third interface to register + A fourth interface to register + The that implements both interfaces + The for this + The created + + + + Register multiple interfaces for a that implements them and create a + + The base interface to register + A second interface to register + A third interface to register + A fourth interface to register + A fifth interface to register + The that implements both interfaces + The for this + The created + Register a without an interface and create a diff --git a/LightweightIocContainer/Registrations/MultipleRegistration.cs b/LightweightIocContainer/Registrations/MultipleRegistration.cs index bebb459..bf57a5c 100644 --- a/LightweightIocContainer/Registrations/MultipleRegistration.cs +++ b/LightweightIocContainer/Registrations/MultipleRegistration.cs @@ -8,12 +8,36 @@ using LightweightIocContainer.Interfaces.Registrations; namespace LightweightIocContainer.Registrations { + /// + /// The base class for every to register multiple interfaces + /// + /// The first interface + public abstract class MultipleRegistration : TypedRegistrationBase, IMultipleRegistration + { + /// + /// The base class for every to register multiple interfaces + /// + /// The of the first interface + /// The of the implementation + /// The of this + protected MultipleRegistration(Type interfaceType1, Type implementationType, Lifestyle lifestyle) + : base(interfaceType1, implementationType, lifestyle) + { + + } + + /// + /// A of s that are registered within this + /// + public List Registrations { get; protected set; } + } + /// /// An to register multiple interfaces for on implementation type /// /// The first interface /// The second interface - public class MultipleRegistration : TypedRegistrationBase, IMultipleRegistration + public class MultipleRegistration : MultipleRegistration, IMultipleRegistration { /// /// An to register multiple interfaces for on implementation type @@ -24,30 +48,193 @@ namespace LightweightIocContainer.Registrations /// The of this public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type implementationType, Lifestyle lifestyle) : base(interfaceType1, implementationType, lifestyle) + { + Registrations = new List() + { + new DefaultRegistration(interfaceType1, implementationType, lifestyle), + new DefaultRegistration(interfaceType2, implementationType, lifestyle) + }; + } + + /// + /// Pass an for each interface that will be invoked when instances of the types are created + /// + /// The first + /// The second + /// The current instance of this + public IMultipleRegistration OnCreate(Action action1, Action action2) + { + foreach (var registration in Registrations) + { + if (registration is IDefaultRegistration interface2Registration) + interface2Registration.OnCreate(action2); + else if (registration is IDefaultRegistration interface1Registration) + interface1Registration.OnCreate(action1); + } + + return this; + } + } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + /// The third interface + public class MultipleRegistration : MultipleRegistration, IMultipleRegistration + { + /// + /// An to register multiple interfaces for on implementation type + /// + /// The of the first interface + /// The of the second interface + /// The of the third interface + /// The of the implementation + /// The of this + public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type interfaceType3, Type implementationType, Lifestyle lifestyle) + : base(interfaceType1, implementationType, lifestyle) { Registrations = new List() { new DefaultRegistration(interfaceType1, implementationType, lifestyle), - new DefaultRegistration(interfaceType2, implementationType, lifestyle) + new DefaultRegistration(interfaceType2, implementationType, lifestyle), + new DefaultRegistration(interfaceType3, implementationType, lifestyle) }; } /// - /// A of s that are registered within this + /// Pass an for each interface that will be invoked when instances of the types are created /// - public List Registrations { get; } + /// The first + /// The second + /// The third + /// The current instance of this + public IMultipleRegistration OnCreate(Action action1, Action action2, Action action3) + { + foreach (var registration in Registrations) + { + if (registration is IDefaultRegistration interface3Registration) + interface3Registration.OnCreate(action3); + else if (registration is IDefaultRegistration interface2Registration) + interface2Registration.OnCreate(action2); + else if (registration is IDefaultRegistration interface1Registration) + interface1Registration.OnCreate(action1); + } + + return this; + } + } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + /// The third interface + /// The fourth interface + public class MultipleRegistration : MultipleRegistration, IMultipleRegistration + { + /// + /// An to register multiple interfaces for on implementation type + /// + /// The of the first interface + /// The of the second interface + /// The of the third interface + /// The of the fourth interface + /// The of the implementation + /// The of this + public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type interfaceType3, Type interfaceType4, Type implementationType, Lifestyle lifestyle) + : base(interfaceType1, implementationType, lifestyle) + { + Registrations = new List() + { + new DefaultRegistration(interfaceType1, implementationType, lifestyle), + new DefaultRegistration(interfaceType2, implementationType, lifestyle), + new DefaultRegistration(interfaceType3, implementationType, lifestyle), + new DefaultRegistration(interfaceType4, implementationType, lifestyle) + }; + } /// /// Pass an for each interface that will be invoked when instances of the types are created /// /// The first /// The second + /// The third + /// The fourth /// The current instance of this - public IMultipleRegistration OnCreate(Action action1, Action action2) + public IMultipleRegistration OnCreate(Action action1, Action action2, Action action3, Action action4) { foreach (var registration in Registrations) { - if (registration is IDefaultRegistration interface2Registration) + if (registration is IDefaultRegistration interface4Registration) + interface4Registration.OnCreate(action4); + else if (registration is IDefaultRegistration interface3Registration) + interface3Registration.OnCreate(action3); + else if (registration is IDefaultRegistration interface2Registration) + interface2Registration.OnCreate(action2); + else if (registration is IDefaultRegistration interface1Registration) + interface1Registration.OnCreate(action1); + } + + return this; + } + } + + /// + /// An to register multiple interfaces for on implementation type + /// + /// The first interface + /// The second interface + /// The third interface + /// The fourth interface + /// The fifth interface + public class MultipleRegistration : MultipleRegistration, IMultipleRegistration + { + /// + /// An to register multiple interfaces for on implementation type + /// + /// The of the first interface + /// The of the second interface + /// The of the third interface + /// The of the fourth interface + /// The of the fifth interface + /// The of the implementation + /// The of this + public MultipleRegistration(Type interfaceType1, Type interfaceType2, Type interfaceType3, Type interfaceType4, Type interfaceType5, Type implementationType, Lifestyle lifestyle) + : base(interfaceType1, implementationType, lifestyle) + { + Registrations = new List() + { + new DefaultRegistration(interfaceType1, implementationType, lifestyle), + new DefaultRegistration(interfaceType2, implementationType, lifestyle), + new DefaultRegistration(interfaceType3, implementationType, lifestyle), + new DefaultRegistration(interfaceType4, implementationType, lifestyle), + new DefaultRegistration(interfaceType5, implementationType, lifestyle) + }; + } + + /// + /// Pass an for each interface that will be invoked when instances of the types are created + /// + /// The first + /// The second + /// The third + /// The fourth + /// The fifth + /// The current instance of this + public IMultipleRegistration OnCreate(Action action1, Action action2, Action action3, Action action4, Action action5) + { + foreach (var registration in Registrations) + { + if (registration is IDefaultRegistration interface5Registration) + interface5Registration.OnCreate(action5); + else if (registration is IDefaultRegistration interface4Registration) + interface4Registration.OnCreate(action4); + else if (registration is IDefaultRegistration interface3Registration) + interface3Registration.OnCreate(action3); + else if (registration is IDefaultRegistration interface2Registration) interface2Registration.OnCreate(action2); else if (registration is IDefaultRegistration interface1Registration) interface1Registration.OnCreate(action1); diff --git a/LightweightIocContainer/Registrations/RegistrationFactory.cs b/LightweightIocContainer/Registrations/RegistrationFactory.cs index 0c4bf61..8f1c0f2 100644 --- a/LightweightIocContainer/Registrations/RegistrationFactory.cs +++ b/LightweightIocContainer/Registrations/RegistrationFactory.cs @@ -46,6 +46,51 @@ namespace LightweightIocContainer.Registrations return new MultipleRegistration(typeof(TInterface1), typeof(TInterface2), typeof(TImplementation), lifestyle); } + /// + /// Register multiple interfaces for a that implements them and create a + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// The that implements both interfaces + /// The for this + /// The created + public IMultipleRegistration Register(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3 + { + return new MultipleRegistration(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TImplementation), lifestyle); + } + + /// + /// Register multiple interfaces for a that implements them and create a + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// A fourth interface to register + /// The that implements both interfaces + /// The for this + /// The created + public IMultipleRegistration Register(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3, TInterface4 + { + return new MultipleRegistration(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TInterface4), typeof(TImplementation), lifestyle); + } + + /// + /// Register multiple interfaces for a that implements them and create a + /// + /// The base interface to register + /// A second interface to register + /// A third interface to register + /// A fourth interface to register + /// A fifth interface to register + /// The that implements both interfaces + /// The for this + /// The created + public IMultipleRegistration Register(Lifestyle lifestyle) where TImplementation : TInterface1, TInterface2, TInterface3, TInterface4, TInterface5 + { + return new MultipleRegistration(typeof(TInterface1), typeof(TInterface2), typeof(TInterface3), typeof(TInterface4), typeof(TInterface5), typeof(TImplementation), lifestyle); + } + /// /// Register a without an interface and create a /// diff --git a/Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs b/Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs index 864aad0..91a5278 100644 --- a/Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs +++ b/Test.LightweightIocContainer/IocContainerInterfaceSegregationTest.cs @@ -23,8 +23,22 @@ namespace Test.LightweightIocContainer { void ThrowFoo(); } + private interface IAnotherBar + { + void ThrowAnotherBar(); + } + + private interface IAnotherFoo + { + void ThrowAnotherFoo(); + } + + private interface IAnotherOne + { + void ThrowAnotherOne(); + } - private class Foo : IFoo, IBar + private class Foo : IFoo, IBar, IAnotherFoo, IAnotherBar, IAnotherOne { public void ThrowFoo() { @@ -35,6 +49,21 @@ namespace Test.LightweightIocContainer { throw new Exception("Bar"); } + + public void ThrowAnotherFoo() + { + throw new Exception("AnotherFoo"); + } + + public void ThrowAnotherBar() + { + throw new Exception("AnotherBar"); + } + + public void ThrowAnotherOne() + { + throw new Exception("AnotherOne"); + } } #endregion TestClasses @@ -54,7 +83,7 @@ namespace Test.LightweightIocContainer } [Test] - public void TestRegistrationOnCreate() + public void TestRegistrationOnCreate2() { _container.Register().OnCreate(bar => bar.ThrowBar(), foo => foo.ThrowFoo()); @@ -65,28 +94,102 @@ namespace Test.LightweightIocContainer Assert.AreEqual("Bar", barException.Message); } + [Test] + public void TestRegistrationOnCreate3() + { + _container.Register().OnCreate(bar => bar.ThrowBar(), foo => foo.ThrowFoo(), anotherFoo => anotherFoo.ThrowAnotherFoo()); + + Exception fooException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("Foo", fooException.Message); + + Exception barException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("Bar", barException.Message); + + Exception anotherFooException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("AnotherFoo", anotherFooException.Message); + } + + [Test] + public void TestRegistrationOnCreate4() + { + _container.Register().OnCreate(bar => bar.ThrowBar(), foo => foo.ThrowFoo(), anotherFoo => anotherFoo.ThrowAnotherFoo(), anotherBar => anotherBar.ThrowAnotherBar()); + + Exception fooException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("Foo", fooException.Message); + + Exception barException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("Bar", barException.Message); + + Exception anotherFooException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("AnotherFoo", anotherFooException.Message); + + Exception anotherBarException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("AnotherBar", anotherBarException.Message); + } + + [Test] + public void TestRegistrationOnCreate5() + { + _container.Register().OnCreate(bar => bar.ThrowBar(), foo => foo.ThrowFoo(), anotherFoo => anotherFoo.ThrowAnotherFoo(), anotherBar => anotherBar.ThrowAnotherBar(), anotherOne => anotherOne.ThrowAnotherOne()); + + Exception fooException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("Foo", fooException.Message); + + Exception barException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("Bar", barException.Message); + + Exception anotherFooException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("AnotherFoo", anotherFooException.Message); + + Exception anotherBarException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("AnotherBar", anotherBarException.Message); + + Exception anotherOneException = Assert.Throws(() => _container.Resolve()); + Assert.AreEqual("AnotherOne", anotherOneException.Message); + } + [Test] public void TestResolveTransient() { - _container.Register(); + _container.Register(); IFoo foo = _container.Resolve(); IBar bar = _container.Resolve(); + IAnotherFoo anotherFoo = _container.Resolve(); + IAnotherBar anotherBar = _container.Resolve(); + IAnotherOne anotherOne = _container.Resolve(); Assert.IsInstanceOf(foo); Assert.IsInstanceOf(bar); + Assert.IsInstanceOf(anotherFoo); + Assert.IsInstanceOf(anotherBar); + Assert.IsInstanceOf(anotherOne); } [Test] public void TestResolveSingleton() { - _container.Register(Lifestyle.Singleton); + _container.Register(Lifestyle.Singleton); IFoo foo = _container.Resolve(); IBar bar = _container.Resolve(); + IAnotherFoo anotherFoo = _container.Resolve(); + IAnotherBar anotherBar = _container.Resolve(); + IAnotherOne anotherOne = _container.Resolve(); Assert.IsInstanceOf(foo); Assert.IsInstanceOf(bar); + Assert.IsInstanceOf(anotherFoo); + Assert.IsInstanceOf(anotherBar); + Assert.IsInstanceOf(anotherOne); + Assert.AreEqual(foo, bar); + Assert.AreEqual(foo, anotherFoo); + Assert.AreEqual(foo, anotherBar); + Assert.AreEqual(foo, anotherOne); + Assert.AreSame(foo, bar); + Assert.AreSame(foo, anotherFoo); + Assert.AreSame(foo, anotherBar); + Assert.AreSame(foo, anotherOne); } } } \ No newline at end of file