#29: mark IUnitTestResolveCallback as deprecated

pull/32/head
Simon Gockner 6 years ago
parent 6e3a1c875e
commit f1e4f5e2f9
  1. 1
      LightweightIocContainer/Interfaces/IIocContainer.cs
  2. 4
      LightweightIocContainer/Interfaces/Registrations/IUnitTestCallbackRegistration.cs
  3. 4
      LightweightIocContainer/IocContainer.cs
  4. 1
      LightweightIocContainer/Registrations/RegistrationFactory.cs
  5. 1
      LightweightIocContainer/Registrations/UnitTestCallbackRegistration.cs
  6. 3
      Test.LightweightIocContainer/IocContainerTest.cs
  7. 2
      Test.LightweightIocContainer/UnitTestCallbackRegistrationTest.cs

@ -59,6 +59,7 @@ namespace LightweightIocContainer.Interfaces
/// <typeparam name="TInterface">The Interface to register</typeparam>
/// <param name="unitTestCallback">The <see cref="ResolveCallback{T}"/> for the callback</param>
/// <returns>The created <see cref="IRegistration"/></returns>
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
IUnitTestCallbackRegistration<TInterface> RegisterUnitTestCallback<TInterface>(ResolveCallback<TInterface> unitTestCallback);
/// <summary>

@ -2,17 +2,21 @@
// Created: 2019-10-15
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
namespace LightweightIocContainer.Interfaces.Registrations
{
/// <summary>
/// A special <see cref="IRegistration"/> that allows to set a <see cref="ResolveCallback{T}"/> as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
/// <typeparam name="TInterface"></typeparam>
[Obsolete("IUnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public interface IUnitTestCallbackRegistration<out TInterface> : IRegistration
{
/// <summary>
/// An <see cref="ResolveCallback{T}"/> that is set as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
[Obsolete("UnitTestResolveCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
ResolveCallback<TInterface> UnitTestResolveCallback { get; }
}
}

@ -115,6 +115,7 @@ namespace LightweightIocContainer
/// <typeparam name="TInterface">The Interface to register</typeparam>
/// <param name="unitTestCallback">The <see cref="ResolveCallback{T}"/> for the callback</param>
/// <returns>The created <see cref="IRegistration"/></returns>
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public IUnitTestCallbackRegistration<TInterface> RegisterUnitTestCallback<TInterface>(ResolveCallback<TInterface> unitTestCallback)
{
IUnitTestCallbackRegistration<TInterface> registration = _registrationFactory.RegisterUnitTestCallback(unitTestCallback);
@ -209,10 +210,13 @@ namespace LightweightIocContainer
T resolvedInstance;
//TODO: remove this #pragma when IUnitTestCallbackRegistration is removed
#pragma warning disable 618
if (registration is IUnitTestCallbackRegistration<T> unitTestCallbackRegistration)
{
resolvedInstance = unitTestCallbackRegistration.UnitTestResolveCallback.Invoke(arguments);
}
#pragma warning restore 618
else if (registration is IRegistrationBase<T> defaultRegistration)
{
if (defaultRegistration.Lifestyle == Lifestyle.Singleton)

@ -66,6 +66,7 @@ namespace LightweightIocContainer.Registrations
return new TypedFactoryRegistration<TFactory>(typeof(TFactory), _iocContainer);
}
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public IUnitTestCallbackRegistration<TInterface> RegisterUnitTestCallback<TInterface>(ResolveCallback<TInterface> unitTestResolveCallback)
{
return new UnitTestCallbackRegistration<TInterface>(typeof(TInterface), unitTestResolveCallback);

@ -12,6 +12,7 @@ namespace LightweightIocContainer.Registrations
/// A special <see cref="IRegistration"/> that allows to set a <see cref="ResolveCallback{T}"/> as a callback that is called on <see cref="IIocContainer.Resolve{T}()"/>
/// </summary>
/// <typeparam name="TInterface"></typeparam>
[Obsolete("UnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public class UnitTestCallbackRegistration<TInterface> : IUnitTestCallbackRegistration<TInterface>
{
/// <summary>

@ -1,3 +1,4 @@
using System;
using JetBrains.Annotations;
using LightweightIocContainer;
using LightweightIocContainer.Exceptions;
@ -179,6 +180,7 @@ namespace Test.LightweightIocContainer
}
[Test]
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public void TestRegisterUnitTestCallback()
{
Assert.DoesNotThrow(() => _iocContainer.RegisterUnitTestCallback<ITest>(delegate {return new Test(); }));
@ -436,6 +438,7 @@ namespace Test.LightweightIocContainer
}
[Test]
[Obsolete("RegisterUnitTestCallback is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public void TestResolveUnitTestCallbackRegistration()
{
ITest callbackTest = new Test();

@ -2,6 +2,7 @@
// Created: 2019-10-15
// Copyright(c) 2019 SimonG. All Rights Reserved.
using System;
using LightweightIocContainer;
using LightweightIocContainer.Interfaces;
using LightweightIocContainer.Interfaces.Registrations;
@ -12,6 +13,7 @@ using NUnit.Framework;
namespace Test.LightweightIocContainer
{
[TestFixture]
[Obsolete("UnitTestCallbackRegistration is deprecated, use `WithFactoryMethod()` from ISingleTypeRegistration instead.")]
public class UnitTestCallbackRegistrationTest
{
private interface ITest

Loading…
Cancel
Save