From f5fefa400ab8a3e81d8a5cc080524536b4964633 Mon Sep 17 00:00:00 2001 From: Simon G Date: Wed, 29 Jan 2020 14:44:40 +0100 Subject: [PATCH] close #38: remove UnitTestCallbackRegistration --- .../Interfaces/IIocContainer.cs | 9 --- .../IUnitTestCallbackRegistration.cs | 22 ------ LightweightIocContainer/IocContainer.cs | 24 +------ .../LightweightIocContainer.xml | 55 -------------- .../Registrations/RegistrationFactory.cs | 6 -- .../UnitTestCallbackRegistration.cs | 46 ------------ .../IocContainerTest.cs | 20 ------ .../UnitTestCallbackRegistrationTest.cs | 72 ------------------- 8 files changed, 1 insertion(+), 253 deletions(-) delete mode 100644 LightweightIocContainer/Interfaces/Registrations/IUnitTestCallbackRegistration.cs delete mode 100644 LightweightIocContainer/Registrations/UnitTestCallbackRegistration.cs delete mode 100644 Test.LightweightIocContainer/UnitTestCallbackRegistrationTest.cs diff --git a/LightweightIocContainer/Interfaces/IIocContainer.cs b/LightweightIocContainer/Interfaces/IIocContainer.cs index 559ba13..62a4434 100644 --- a/LightweightIocContainer/Interfaces/IIocContainer.cs +++ b/LightweightIocContainer/Interfaces/IIocContainer.cs @@ -99,15 +99,6 @@ namespace LightweightIocContainer.Interfaces /// The created ITypedFactoryRegistration RegisterFactory(); - /// - /// Register an Interface with an as a callback that is called when is called - /// - /// The Interface to register - /// The for the callback - /// The created - [Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - IUnitTestCallbackRegistration RegisterUnitTestCallback(ResolveCallback unitTestCallback); - /// /// Gets an instance of the given /// diff --git a/LightweightIocContainer/Interfaces/Registrations/IUnitTestCallbackRegistration.cs b/LightweightIocContainer/Interfaces/Registrations/IUnitTestCallbackRegistration.cs deleted file mode 100644 index d10f74e..0000000 --- a/LightweightIocContainer/Interfaces/Registrations/IUnitTestCallbackRegistration.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Author: Gockner, Simon -// Created: 2019-10-15 -// Copyright(c) 2019 SimonG. All Rights Reserved. - -using System; - -namespace LightweightIocContainer.Interfaces.Registrations -{ - /// - /// A special that allows to set a as a callback that is called on - /// - /// - [Obsolete("IUnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public interface IUnitTestCallbackRegistration : IRegistration - { - /// - /// An that is set as a callback that is called on - /// - [Obsolete("UnitTestResolveCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - ResolveCallback UnitTestResolveCallback { get; } - } -} \ No newline at end of file diff --git a/LightweightIocContainer/IocContainer.cs b/LightweightIocContainer/IocContainer.cs index 43e9c84..b6f9bcc 100644 --- a/LightweightIocContainer/IocContainer.cs +++ b/LightweightIocContainer/IocContainer.cs @@ -183,21 +183,6 @@ namespace LightweightIocContainer return registration; } - /// - /// Register an Interface with an as a callback that is called when is called - /// - /// The Interface to register - /// The for the callback - /// The created - [Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public IUnitTestCallbackRegistration RegisterUnitTestCallback(ResolveCallback unitTestCallback) - { - IUnitTestCallbackRegistration registration = _registrationFactory.RegisterUnitTestCallback(unitTestCallback); - Register(registration); - - return registration; - } - /// /// Add the to the the /// @@ -298,14 +283,7 @@ namespace LightweightIocContainer T resolvedInstance; - //TODO: remove this #pragma when IUnitTestCallbackRegistration is removed -#pragma warning disable 618 - if (registration is IUnitTestCallbackRegistration unitTestCallbackRegistration) - { - resolvedInstance = unitTestCallbackRegistration.UnitTestResolveCallback.Invoke(arguments); - } -#pragma warning restore 618 - else if (registration is IRegistrationBase defaultRegistration) + if (registration is IRegistrationBase defaultRegistration) { if (defaultRegistration.Lifestyle == Lifestyle.Singleton) resolvedInstance = GetOrCreateSingletonInstance(defaultRegistration, arguments, resolveStack); diff --git a/LightweightIocContainer/LightweightIocContainer.xml b/LightweightIocContainer/LightweightIocContainer.xml index da50bc8..436ab93 100644 --- a/LightweightIocContainer/LightweightIocContainer.xml +++ b/LightweightIocContainer/LightweightIocContainer.xml @@ -416,14 +416,6 @@ The abstract typed factory to register The created - - - Register an Interface with an as a callback that is called when is called - - The Interface to register - The for the callback - The created - Gets an instance of the given @@ -672,17 +664,6 @@ A that implements a - - - A special that allows to set a as a callback that is called on - - - - - - An that is set as a callback that is called on - - An internal placeholder that is used during the resolving process @@ -784,14 +765,6 @@ The abstract typed factory to register The created - - - Register an Interface with an as a callback that is called when is called - - The Interface to register - The for the callback - The created - Add the to the the @@ -1322,34 +1295,6 @@ The The current instance of this - - - A special that allows to set a as a callback that is called on - - - - - - A special that allows to set a as a callback that is called on - - The of the interface - The that is set as a callback - - - - The name of the - - - - - The of the Interface that is registered with this - - - - - An that is set as a callback that is called on - - The resolve callback delegate diff --git a/LightweightIocContainer/Registrations/RegistrationFactory.cs b/LightweightIocContainer/Registrations/RegistrationFactory.cs index ef66ee8..f87383c 100644 --- a/LightweightIocContainer/Registrations/RegistrationFactory.cs +++ b/LightweightIocContainer/Registrations/RegistrationFactory.cs @@ -123,11 +123,5 @@ namespace LightweightIocContainer.Registrations { return new TypedFactoryRegistration(typeof(TFactory), _iocContainer); } - - [Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public IUnitTestCallbackRegistration RegisterUnitTestCallback(ResolveCallback unitTestResolveCallback) - { - return new UnitTestCallbackRegistration(typeof(TInterface), unitTestResolveCallback); - } } } \ No newline at end of file diff --git a/LightweightIocContainer/Registrations/UnitTestCallbackRegistration.cs b/LightweightIocContainer/Registrations/UnitTestCallbackRegistration.cs deleted file mode 100644 index c489510..0000000 --- a/LightweightIocContainer/Registrations/UnitTestCallbackRegistration.cs +++ /dev/null @@ -1,46 +0,0 @@ -// Author: Gockner, Simon -// Created: 2019-10-15 -// Copyright(c) 2019 SimonG. All Rights Reserved. - -using System; -using LightweightIocContainer.Interfaces; -using LightweightIocContainer.Interfaces.Registrations; - -namespace LightweightIocContainer.Registrations -{ - /// - /// A special that allows to set a as a callback that is called on - /// - /// - [Obsolete("UnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public class UnitTestCallbackRegistration : IUnitTestCallbackRegistration - { - /// - /// A special that allows to set a as a callback that is called on - /// - /// The of the interface - /// The that is set as a callback - public UnitTestCallbackRegistration(Type interfaceType, ResolveCallback unitTestResolveCallback) - { - InterfaceType = interfaceType; - UnitTestResolveCallback = unitTestResolveCallback; - - Name = InterfaceType.Name; - } - - /// - /// The name of the - /// - public string Name { get; } - - /// - /// The of the Interface that is registered with this - /// - public Type InterfaceType { get; } - - /// - /// An that is set as a callback that is called on - /// - public ResolveCallback UnitTestResolveCallback { get; } - } -} \ No newline at end of file diff --git a/Test.LightweightIocContainer/IocContainerTest.cs b/Test.LightweightIocContainer/IocContainerTest.cs index da80733..ac56340 100644 --- a/Test.LightweightIocContainer/IocContainerTest.cs +++ b/Test.LightweightIocContainer/IocContainerTest.cs @@ -1,4 +1,3 @@ -using System; using JetBrains.Annotations; using LightweightIocContainer; using LightweightIocContainer.Exceptions; @@ -209,13 +208,6 @@ namespace Test.LightweightIocContainer Assert.Throws(() => _iocContainer.RegisterFactory()); } - [Test] - [Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public void TestRegisterUnitTestCallback() - { - Assert.DoesNotThrow(() => _iocContainer.RegisterUnitTestCallback(delegate {return new Test(); })); - } - [Test] public void TestResolveNotRegistered() { @@ -474,18 +466,6 @@ namespace Test.LightweightIocContainer Assert.AreNotSame(resolvedTest3, resolvedTest5); } - [Test] - [Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public void TestResolveUnitTestCallbackRegistration() - { - ITest callbackTest = new Test(); - - _iocContainer.RegisterUnitTestCallback(delegate { return callbackTest; }); - ITest test = _iocContainer.Resolve(); - - Assert.AreEqual(callbackTest, test); - } - [Test] public void TestResolveSingleTypeRegistrationWithFactoryMethod() { diff --git a/Test.LightweightIocContainer/UnitTestCallbackRegistrationTest.cs b/Test.LightweightIocContainer/UnitTestCallbackRegistrationTest.cs deleted file mode 100644 index f9392db..0000000 --- a/Test.LightweightIocContainer/UnitTestCallbackRegistrationTest.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Author: Gockner, Simon -// Created: 2019-10-15 -// Copyright(c) 2019 SimonG. All Rights Reserved. - -using System; -using LightweightIocContainer; -using LightweightIocContainer.Interfaces; -using LightweightIocContainer.Interfaces.Registrations; -using LightweightIocContainer.Registrations; -using Moq; -using NUnit.Framework; - -namespace Test.LightweightIocContainer -{ - [TestFixture] - [Obsolete("UnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")] - public class UnitTestCallbackRegistrationTest - { - private interface ITest - { - int Count { get; } - string Name { get; } - bool Testing { get; } - } - - private class Test : ITest - { - public Test() - { - Count = -1; - Name = "Test"; - Testing = false; - } - - public Test(int count, string name, bool testing) - { - Count = count; - Name = name; - Testing = testing; - } - - public int Count { get; } - public string Name { get; } - public bool Testing { get; } - } - - [Test] - public void TestUnitTestResolveCallback() - { - RegistrationFactory registrationFactory = new RegistrationFactory(new Mock().Object); - - ITest test = new Test(); - IUnitTestCallbackRegistration testCallbackRegistration = registrationFactory.RegisterUnitTestCallback(delegate { return test; }); - - Assert.AreEqual(test, testCallbackRegistration.UnitTestResolveCallback.Invoke()); - } - - [Test] - public void TestUnitTestResolveCallbackWithParams() - { - RegistrationFactory registrationFactory = new RegistrationFactory(new Mock().Object); - IUnitTestCallbackRegistration testCallbackRegistration = - registrationFactory.RegisterUnitTestCallback(new ResolveCallback(parameters => new Test((int) parameters[0], (string) parameters[1], (bool) parameters[2]))); - - ITest test = testCallbackRegistration.UnitTestResolveCallback.Invoke(4, "SomeTest", true); - - Assert.AreEqual(4, test.Count); - Assert.AreEqual("SomeTest", test.Name); - Assert.True(test.Testing); - } - } -} \ No newline at end of file