You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If in DI TryAddScoped do not add service to collection if it's already there, then expected behavior for TryDecorate should be the same. But it not passing this test:
public class TestTest
{
public interface IExampleInterface { }
public class ExampleImplementation : IExampleInterface { }
public class ExampleDecorator(IExampleInterface impelmentation) : IExampleInterface { public IExampleInterface Implementation { get; set; } = impelmentation; }
[Fact]
public void TestTryDecorate()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddScoped<IExampleInterface, ExampleImplementation>();
serviceCollection.TryDecorate(typeof(IExampleInterface), typeof(ExampleDecorator));
var initCount = serviceCollection.Count;
serviceCollection.TryDecorate(typeof(IExampleInterface), typeof(ExampleDecorator));
serviceCollection.TryDecorate(typeof(IExampleInterface), typeof(ExampleDecorator));
var obj = serviceCollection.BuildServiceProvider()
.GetRequiredService<IExampleInterface>();
obj.Should().BeOfType<ExampleDecorator>();
var obj2 = obj as ExampleDecorator;
obj2!.Implementation.Should().BeOfType<ExampleImplementation>();
}
}
The text was updated successfully, but these errors were encountered:
TryAdd* and TryDecorate are two different things. It works exactly as expected. TryDecorate will (re)decorate everything every time it's called and return true. If nothing is found, it returns false.
If in DI TryAddScoped do not add service to collection if it's already there, then expected behavior for TryDecorate should be the same. But it not passing this test:
The text was updated successfully, but these errors were encountered: