-
-
Notifications
You must be signed in to change notification settings - Fork 278
Service is registered twice #270
Copy link
Copy link
Open
Description
When I try to register a scoped service, it seems the interface is registered as scoped, but the concrete class is also registered as transient?
using Microsoft.Extensions.DependencyInjection;
using System.Linq;
using Xunit;
namespace Scrutor.Tests;
public class RegistrationTest : TestBase
{
private IServiceCollection Collection { get; } = new ServiceCollection();
[Fact]
public void ShouldRegisterOnce()
{
Collection.Scan(scan => scan
.FromTypes(typeof(MyClass))
.AddClasses(classes => classes.AssignableTo<MyInterface>())
.As<MyInterface>()
.WithScopedLifetime());
Assert.Single(Collection);
}
}
public interface MyInterface
{
}
public class MyClass : MyInterface
{
}
Message:
Assert.Single() Failure: The collection contained 2 items
Collection: [ServiceType: Scrutor.Tests.MyClass Lifetime: Transient ImplementationType: Scrutor.Tests.MyClass, ServiceType: Scrutor.Tests.MyInterface Lifetime: Scoped ImplementationType: Scrutor.Tests.MyClass]
Stack Trace:
FluentKeyedServiceTests.CanRegisterKeyedServiceUsingStaticProperty() line 20
MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels